Error: Bad Gateway 502 when opening Google App Engine Python Domain
Error: Bad Gateway 502 when opening Google App Engine Python Domain
当我访问我的网站 (https://osm-messaging-platform.appspot.com) 时,我在主网页上收到此错误:
502 Bad Gateway. nginx/1.14.0 (Ubuntu).
这真的很奇怪,因为当我 运行 它在本地
python app.py
我没有收到任何错误,我的应用程序和网站加载正常。
我已经尝试查找它,但我在 stack overflow 上找到的大部分答案要么没有错误,要么与我无关。这是我查看 GCloud 日志时的错误:
019-02-07 02:07:05 default[20190206t175104] Traceback (most recent
call last): File "/env/lib/python3.7/site-
packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process() File "/env/lib/python3.7/site-
packages/gunicorn/workers/gthread.py", line 104, in init_process
super(ThreadWorker, self).init_process() File
"/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line
129, in init_process self.load_wsgi() File
"/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line
138, in load_wsgi self.wsgi = self.app.wsgi() File
"/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in
wsgi self.callable = self.load() File
"/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52,
in load return self.load_wsgiapp() File
"/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41,
in load_wsgiapp return util.import_app(self.app_uri) File
"/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in
import_app __import__(module) ModuleNotFoundError: No module
named 'main'
2019-02-07 02:07:05 default[20190206t175104] [2019-02-07 02:07:05
+0000] [25] [INFO] Worker exiting (pid: 25)
2019-02-07 02:07:05 default[20190206t175104] [2019-02-07 02:07:05
+0000] [8] [INFO] Shutting down: Master
2019-02-07 02:07:05 default[20190206t175104] [2019-02-07 02:07:05
+0000] [8] [INFO] Reason: Worker failed to boot.
下面是我的 app.yaml 文件的内容:
runtime: python37
handlers:
# This configures Google App Engine to serve the files in the app's
static
# directory.
- url: /static
static_dir: static
- url: /.*
script: auto
我希望它能显示我的网站,但它没有。有人可以帮忙吗?
错误的产生是因为 App Engine 标准 Python37 运行时默认处理 main.py
文件中的请求。我猜你没有这个文件,你正在处理 app.py
文件中的请求。
日志回溯也指向它:ModuleNotFoundError: No module named 'main'
将 app.py
文件的名称更改为 main.py
,然后重试。
作为一般规则,建议遵循 App Engine Standard documention 中存在的此文件结构:
your-app/
app.yaml
main.py
requirements.txt
static/
script.js
style.css
templates/
index.html
我相信这对你的情况来说有点过分了,但如果你需要一个自定义 entrypoint read this Python3 runtime documentation 来了解更多关于如何配置它的信息。
我的错误是将主应用命名为 "main",这与 main.py 冲突。它在本地运行良好,因为它没有使用 main.py。我将其更改为 root,一切正常。我花了一整天才解决。
我通过更改主机解决了 main.py
中的问题:
app.run(host="127.0.0.1", port=8080, debug=True)
至
app.run(host="0.0.0.0", port=8080, debug=True)
当我访问我的网站 (https://osm-messaging-platform.appspot.com) 时,我在主网页上收到此错误:
502 Bad Gateway. nginx/1.14.0 (Ubuntu).
这真的很奇怪,因为当我 运行 它在本地
python app.py
我没有收到任何错误,我的应用程序和网站加载正常。
我已经尝试查找它,但我在 stack overflow 上找到的大部分答案要么没有错误,要么与我无关。这是我查看 GCloud 日志时的错误:
019-02-07 02:07:05 default[20190206t175104] Traceback (most recent
call last): File "/env/lib/python3.7/site-
packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process() File "/env/lib/python3.7/site-
packages/gunicorn/workers/gthread.py", line 104, in init_process
super(ThreadWorker, self).init_process() File
"/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line
129, in init_process self.load_wsgi() File
"/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line
138, in load_wsgi self.wsgi = self.app.wsgi() File
"/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in
wsgi self.callable = self.load() File
"/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52,
in load return self.load_wsgiapp() File
"/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41,
in load_wsgiapp return util.import_app(self.app_uri) File
"/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in
import_app __import__(module) ModuleNotFoundError: No module
named 'main'
2019-02-07 02:07:05 default[20190206t175104] [2019-02-07 02:07:05
+0000] [25] [INFO] Worker exiting (pid: 25)
2019-02-07 02:07:05 default[20190206t175104] [2019-02-07 02:07:05
+0000] [8] [INFO] Shutting down: Master
2019-02-07 02:07:05 default[20190206t175104] [2019-02-07 02:07:05
+0000] [8] [INFO] Reason: Worker failed to boot.
下面是我的 app.yaml 文件的内容:
runtime: python37
handlers:
# This configures Google App Engine to serve the files in the app's
static
# directory.
- url: /static
static_dir: static
- url: /.*
script: auto
我希望它能显示我的网站,但它没有。有人可以帮忙吗?
错误的产生是因为 App Engine 标准 Python37 运行时默认处理 main.py
文件中的请求。我猜你没有这个文件,你正在处理 app.py
文件中的请求。
日志回溯也指向它:ModuleNotFoundError: No module named 'main'
将 app.py
文件的名称更改为 main.py
,然后重试。
作为一般规则,建议遵循 App Engine Standard documention 中存在的此文件结构:
your-app/
app.yaml
main.py
requirements.txt
static/
script.js
style.css
templates/
index.html
我相信这对你的情况来说有点过分了,但如果你需要一个自定义 entrypoint read this Python3 runtime documentation 来了解更多关于如何配置它的信息。
我的错误是将主应用命名为 "main",这与 main.py 冲突。它在本地运行良好,因为它没有使用 main.py。我将其更改为 root,一切正常。我花了一整天才解决。
我通过更改主机解决了 main.py
中的问题:
app.run(host="127.0.0.1", port=8080, debug=True)
至
app.run(host="0.0.0.0", port=8080, debug=True)