Question

502 Bad Gateway : connect() failed (111: Unknown error) while connecting to upstream

Hi I have a MERN stack app and it always worked like charm until this morning when we suddenly got a 502 Bad Gateway(without touching anything). I’ve seen another Post on here which is resolved but any of the steps in that post didn’t help me anything at all.

Not sure, how can I find out? Operating system: Ubuntu 18.04

Expected behavior: To work again like before

Actual behavior: A 502 Bad Gateway

Error log from /var/log/nginx/error.log looks like this

2021/09/23 16:34:25 [error] 23460#23460: *11 connect() failed (111: Unknown error) while connecting to upstream, client: x.x.x.x, server: 
, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "x.x.x.x"

Would appreciate your help, Thanks

Show comments

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.

Accepted Answer

Hello,

The error indicates that your Node service is not running so the Nginx service is unable to connect.

What you need to do is to start your Node service. This would depend on your personal setup, but for example if you are using pm2, you could get a list of the available services with pm2 list and then you can start your application with pm2 start your_app_name.

If you do not use pm2, what I could suggest is running the history command so that you could see what were the previous commands executed on the server which could point you in the right direction on how the Node services was first setup and started.

Let me know how it goes! Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel