NGINX Proxy Pass to NodeJS App: Returning 502 error

502configurationnginxPROXY

I'm trying to setup NGINX as the frontend of my NodeJS app, which is live on 127.0.0.1:3000, but i can't resolve this 502 error. NGINX is locally reachable at http://55.55.55.5/ or http://dev.example

dev.example (file in: /etc/nginx/sites-available and symlinked to sites-enabled)

upstream up_dev.example {
    server 127.0.0.1:3000;
}

server {
    listen 0.0.0.0:80;
    server_name dev.example example;
    access_log /var/log/nginx/dev.example.log;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://up_dev.example/;
      proxy_redirect off;
    }
 }

error.log

2014/09/17 19:38:26 [error] 1679#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 55.55.55.1, server: , request: "GET / HTTP/1.1", upstream:$

Best Answer

It could also be SELinux that's preventing the connection being made as httpd_can_network_connect is off by default.

getsebool httpd_can_network_connect

Check if this is turned on. If not, turn it on by running

setsebool -P httpd_can_network_connect on

The -P means persistent changes so the new boolean will still be in effect even after a reboot.