Question

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

Posted September 23, 2021 238 views
NginxDigitalOceanUbuntu 20.04

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

1 comment
  • Hi, I have set up on gke, k8s version 1.20, 2 application pods are deployed backpffice and hac with service type load balancer,and my task is to deploy ingress on gke, so I have used nginx ingress controller and a I defined ingress rules , but when I acccess first I got backend services are unknown, later I have added annotations so that unknown backend is disappeared.but when I try to access iam getting 502 bad gateway when I use service port as 80 on ingress rule and when u use service port 442 on ingress rule I got bad re request port and path need TLS. Please help me.. and by the way we r using container ports for http: 8081 and https: 8088 on manifest and these r ubuntu is.
    And I went inside pod only 8088 opened 8081 port is not opened.
    Do ineed to chane any configuration??

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

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