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


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!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.