node.js app with nginx 502 bad gateway error
Replace
proxy_pass https://node_app_production;
with
proxy_pass http://node_app_production;
Restart the nginx and you should be all set. See nginx proxy pass Node, SSL?
I've resolved the issue with 2 steps.
- Check
/var/log/nginx/error.log
connect() failed (111: Connection refused) while connecting to upstream, client: *.*.*.*, server: *.*.*.*, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "*.*.*.*"
Upstream was still 127.0.0.1:8000
even if I set upstream to 127.0.0.1:3000
in nginx conf file.
- Replace
server 127.0.0.1:8000
withserver 127.0.0.1:3000
in/etc/nginx/conf.d/virtual.conf
and restart nginx.
server {
listen 80;
server_name SERVER_IP_ADDRESS;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
sudo /etc/init.d/nginx restart
Finally, it works with no 502 error.