NGINX "502 bad gateway request" when making a 'GET' request

Posted April 1, 2018 9.4k views


I’m running nodejs app on a droplet and everything works fine, but when I try to make a GET request to my server I end up with a 502 error. The get is pointed to Everything worked fine, when I run the server locally with npm start.

This is the error log of nginx:

2018/04/01 20:17:02 [error] 22119#22119: *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

And my nginx config:


        location / {
                proxy_pass http://localhost:5000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;


I tried the advice on another thread to change “localhost” to “ ”, but nothing has changed. It is possible that something is wrong with my node app code, so I’ll link it here: (

Any help would be greatly appreciated.

Thank you!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You may want to update your node.js app to specify the IP address to listen on. This may resolve the issue but will also ensure that your node.js app is not listening publicly and only to the local requests from nginx.