Google App Engine 502 (Bad Gateway) with NodeJS
502 Bad Gateway is usually an error on the Nginx side. Unfortunately those logs are not surfaced to Cloud Logging, yet.
A lot of times the problem is that your HTTP packets are too big for the buffers or something similar. The way you can see the nginx log is something like this:
- Use just 1 VM. This isn't strictly necessary, but a lot of times it makes it easier to debug your application if you know that your requests on the one machine. You can accomplish this by adding this to your app.yaml:
manual_scaling:
instances: 1
then re-deploy
Switch the VM from "Google owned" to self-managed. This can be done in the Cloud Console. Go to Compute Engine, instances, click on the instance name that matches the App Engine version, and you should see an option to switch it to self-managed.
gcloud compute ssh <instance name>
to SSH to the machinedocker ps
to see your running containers. Look for the container named nginx and grab its id.Once you have a container ID, you should be able to
docker exec -it <container id> -- cat /var/log/nginx/error.log
. You might want tols
that whole log directory.
You will likely see an error there which will be a bigger hint as to what's going wrong.
I know this is way more complicated than it should be :-\ If you have any problems with the steps above, leave a comment. If you do find an error and you're not sure what to do with it, also leave a comment.
just make sure that your server listens on 8080 port https://cloud.google.com/appengine/docs/flexible/custom-runtimes/build#listen_to_port_8080