Skip to content

Instantly share code, notes, and snippets.

@kematzy
Last active August 29, 2015 14:03
Show Gist options
  • Save kematzy/5a37a8a73e40299d237d to your computer and use it in GitHub Desktop.
Save kematzy/5a37a8a73e40299d237d to your computer and use it in GitHub Desktop.
Phusion passenger ubuntu 14.04 nginx node js 403 Forbidden
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end("hello from NodeJS App via Phusion Passenger with nginx!\n");
});
server.listen(3000);
kematzy@vps1:/var/sites$ ls -al
total 24K
drwxr-xr-x 6 root root 4.0K Jun 29 01:47 .
drwxr-xr-x 13 root root 4.0K Jun 23 05:57 ..
drwxr-xr-x 3 kematzy root 4.0K Jun 23 05:57 sms.example.com
drwxr-xr-x 3 root root 4.0K Jun 23 06:10 default
kematzy@vps1:/var/sites/sms.example.com$ ls -al
total 12K
drwxr-xr-x 3 kematzy root 4.0K Jun 23 05:57 .
drwxr-xr-x 6 root root 4.0K Jun 29 01:47 ..
drwxr-xr-x 4 kematzy root 4.0K Jun 29 20:58 current
kematzy@vps1:/var/sites/sms.example.com/current$ ls -al
total 20K
drwxr-xr-x 4 kematzy root 4.0K Jun 29 20:58 .
drwxr-xr-x 3 kematzy root 4.0K Jun 23 05:57 ..
-rw-r--r-- 1 kematzy root 236 Jun 29 20:58 app.js
drwxr-xr-x 4 kematzy root 4.0K Jun 30 21:32 public
drwxrwxr-x 2 kematzy root 4.0K Jun 29 21:05 tmp
kematzy@vps1:/var/sites/sms.example.com/current/public$ ls -al
total 32K
drwxr-xr-x 4 kematzy root 4.0K Jun 30 21:32 .
drwxr-xr-x 4 kematzy root 4.0K Jun 29 20:58 ..
drwxrwxr-x 2 kematzy root 4.0K Jun 29 02:28 css
-rw-rw-r-- 1 kematzy root 127 Jun 29 02:28 favicon.ico
drwxrwxr-x 2 kematzy root 4.0K Jun 29 02:28 images
-rw-rw-r-- 1 kematzy root 17 Jun 23 06:03 -index.html
-rw-r--r-- 1 kematzy root 6.5K Jun 29 21:01 -index.php
### sms.example.com
server {
# listen 80;
# listen [::]:80;
# listen 443 ssl;
# root /usr/share/nginx/html;
root /var/sites/sms.example.com/current/public;
passenger_enabled on;
index index.html index.php index.htm;
# Make site accessible from http://localhost/
server_name sms.example.com;
# ssl_certificate /etc/nginx/ssl/nginx.crt;
# ssl_certificate_key /etc/nginx/ssl/nginx.key;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
## Basic Settings ##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
## Logging Settings ##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
## Gzip Settings ##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
## nginx-naxsi config ##
# Uncomment it if you installed nginx-naxsi
# include /etc/nginx/naxsi_core.rules;
## Phusion Passenger config ##
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
## Virtual Host Configs ##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
@FooBarWidget
Copy link

It's because of the location / in your server block. If you have any location blocks, then you must re-specify passenger_enabled on inside it, otherwise Nginx will disable it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment