Skip to main content
 首页 » 编程设计

python之使用 elasticbeanstalk 部署 Flask 时出现 AWS mod_wsgi 错误

2025年05月04日14落叶无声

在 elasticbeanstalk 上使用 flask 出现以下错误:

/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 命令行界面来部署 flask 应用程序。

请您参考如下方法:

您正在生产中使用 app.run。不要在生产中使用开发服务器。

mod_wsgi,与任何 WSGI 应用程序服务器一样,期望在导入时找到一个 application 实例,但您运行的是开发服务器。

防止在导入时运行开发服务器。根据您的 mod_wsgi 设置,它也可能需要名称 application 而不是 app。

application = app 
 
if __name__ == '__main__': 
    app.run()