Background:
I use a Nginx+NodeJS structure to run the website. The server has quite some traffic like 300 concurrent people online. Visiting all kind of pages. And I use pm2
to manage my node apps.
Problem:
However, when I restart the node server with pm2 restart xxx
, in a short duration (like 15 seconds), the users will encounter a 502
error. And accordingly, there is “connect() failed (111: Connection refused)” in the log.
According to one other question on SO.
A 502 Bad Gateway error usually suggests that the proxy (Nginx in NodeJS's case) can't find a destination to route the traffic to.
So I guess the error is occurring because of the moment that a user requests the server while the Node hasn't ready for its business. So my Nginx couldn't "contact" my nodejs and threw a 502 error.
Is there any way to fix this?