AaronDT
AaronDT

Reputation: 4050

Google Cloud App Engine: 502 Bad Gateway (nginx) error with Flask App

I am running a Flask app on Google Cloud App Engine (flex). Running it locally works just fine, but once it deploys I get a 502 Bad Gateway error (nginx). Now I would like to figure out what causes this, but I am not able to find any option to view the console logs that my app creates.

Since it works just fine on my local environment, my current workflow to solve this issue involves changing my code locally and deploying it to see if it works afterwards, but each deployment takes over 30min only to figure out it still does not work. There must be a way to do this more efficiently.

Following the docs https://cloud.google.com/appengine/docs/flexible/python/debugging-an-instance I was able to SSH into my instance in debug-mode and launch the Flask app from the Cloud Shell, however it tells me to access it on http://127.0.0.1:8080/ which I can't access from the cloud server. Hence I can't navigate the webpage in order to reproduce the 502 error and then see the output in the console.

How can I figure out what causes the 502 error on the server?

Upvotes: 12

Views: 14497

Answers (1)

radhikesh93
radhikesh93

Reputation: 940

Had the similar issue. Found that app engine looks for app variable in main.py file. My final app.yaml looks like below.

app.yaml

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
 python_version: 3

and had requirements.txt, which looks like below.

requirements.txt

Flask==1.1.1
gunicorn==20.0.4

Upvotes: 6

Related Questions