502 Connection refused while connecting to upstream : modify Nginx upstream on Google App Engine

Solution 1:

'502' usually means that the nginx proxy that is responsible for handling requests for an App Engine Flexible instance has not been able to get in contact with your application and deems it to be unhealthy. This is done via health checks that nginx performs.

To test that this is indeed the case you can simply disable health checks in your yaml configuration file and the 502s should go away. Note that there are other higher level health checks in place that may still run and produce other 502s if your application is too busy to respond.


To ensure that health checks are handled by your application, your application must be able to respond to concurrent requests using asynchronous programming. There are many public guides available covering Async Node.js programming and it is highly recommended to investigate these paradigms when coding an application for the cloud.