使用 elasticbeanstalk 部署 Flask 时出现 AWS mod_wsgi 错误
Posted
技术标签:
【中文标题】使用 elasticbeanstalk 部署 Flask 时出现 AWS mod_wsgi 错误【英文标题】:AWS mod_wsgi error when deploying Flask with elasticbeanstalk 【发布时间】:2015-11-01 04:39:51 【问题描述】:在 elasticbeanstalk 上使用烧瓶时出现以下错误:
/opt/python/run/venv/bin/python3: can't open file 'mod_wsgi': [Errno 2] No such file or directory
[Sat Aug 08 23:43:35.994357 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] mod_wsgi (pid=7748): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Sat Aug 08 23:43:35.994407 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] mod_wsgi (pid=7748): SystemExit exception raised by WSGI script '/opt/python/current/app/application.py' ignored.
[Sat Aug 08 23:43:35.994449 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] Traceback (most recent call last):
[Sat Aug 08 23:43:35.994511 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/current/app/application.py", line 3, in <module>
[Sat Aug 08 23:43:35.994518 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] app.run(debug=True)
[Sat Aug 08 23:43:35.994553 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 772, in run
[Sat Aug 08 23:43:35.994560 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] run_simple(host, port, self, **options)
[Sat Aug 08 23:43:35.994590 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/serving.py", line 623, in run_simple
[Sat Aug 08 23:43:35.994596 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] reloader_type)
[Sat Aug 08 23:43:35.994624 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/_reloader.py", line 231, in run_with_reloader
[Sat Aug 08 23:43:35.994630 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] sys.exit(reloader.restart_with_reloader())
[Sat Aug 08 23:43:35.994652 2015] [:error] [pid 7748] [remote 127.0.0.1:45363] SystemExit: 2
我正在使用 elasticbeanstalk 命令行界面来部署烧瓶应用程序。
【问题讨论】:
【参考方案1】:您在生产中使用app.run
。不要在生产中使用开发服务器。
mod_wsgi
与任何 WSGI 应用服务器一样,希望在导入时找到 application
实例,但您正在运行开发服务器。
防止在导入时运行开发服务器。根据您的 mod_wsgi
设置,它可能还需要名称 application
而不是 app
。
application = app
if __name__ == '__main__':
app.run()
【讨论】:
以上是关于使用 elasticbeanstalk 部署 Flask 时出现 AWS mod_wsgi 错误的主要内容,如果未能解决你的问题,请参考以下文章
使用 elasticbeanstalk 部署 Flask 时出现 AWS mod_wsgi 错误
使用 AWS Elasticbeanstalk 部署 Django 应用程序时出现 WSGIPath 错误
无法将多容器 docker 部署到 ElasticBeanstalk
如何使用aws elasticbeanstalk中的钩子运行部署后脚本?