I cannot get Passenger to start my Nodejs (iojs) application on restarting nginx. I've followed the tutorials and installed the prerequisites:
$ nginx -V
nginx version: nginx/1.8.0
configure arguments: –with-cc-opt='-g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat ……… –add-module=/tmp/buildd/nginx-1.8.0/debian/modules/passenger/ext/nginx
in the http
block enabled:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;
passenger_nodejs /usr/local/bin/node;
passenger_default_user staging;
passenger_default_group www-data;
Then in the server block:
upstream instance {
# point to node instance
server 127.0.0.1:9000;
}
# for websockets
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 3000;
server_name localhost;
set $app_root /home/staging/public_html;
root $app_root/tmp;
passenger_enabled on;
# point to where the app.js file is
passenger_app_root $app_root;
passenger_sticky_sessions on;
location / {
proxy_pass http://instance;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto $scheme;
}
# all static non-scripts are here
location /public/ {
alias $app_root/app/assets/;
}
}
Then restarting nginx I try to load up the page & in the error logs I see:
… Starting Passenger watchdog...
… Starting Passenger core...
… Passenger core running in multi-application mode.
… Passenger core online, PID 26585
… Starting Passenger UstRouter...
… Passenger UstRouter online, PID 26590
… [error] 26736#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 188.102.152.94, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:9000/", host: "staging.chatterplot.com:3000"
Going to the url gives me a 502 bad gateway.
I haven't seen any nginx server block examples that are similar so I get the feeling I'm doing some things very wrong.
Best Answer
It turns out the reason passenger wasn't starting was because it seems that it requires the
location /
block not to proxy request but to handle it itself. The following configuration did the trick.One other thing which wasn't clear to me from the beginning is that passenger/nginx takes the public directory and makes everything there accessible without
/public
in the url.So any requests with
/public/images/logo.png
are simply/images/logo.png