django - AWS Elastic Beanstalk:WSGI 路径不正确?
问题描述
我正在尝试将我的第一个应用程序部署到 EB 并跟随这个教程:https ://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
不幸的是,在部署最终应用程序时,我仍然收到 502 错误。我很困惑,因为我已经按照指示前往发球台了。
我收到以下错误
ImportError: Failed to find application, did you mean 'ebdjango/wsgi:application'?
我不确定这意味着什么。根据说明,我编辑了 django.config 文件以包含以下文本:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango/wsgi.py
这似乎与我的文件结构相匹配:
- ebdjango
-.ebextensions
- django.config
- .elasticbeanstalk
- ebdjango
_ __init__.py
- settings.py
- urls.py
- wsgi.py
- manage.py
- requirements.txt
所以配置文件设置正确,对吧?
我正在运行 Python 3.7 和 Django 2.2。
我知道 EB 搜索 application.py,我认为配置文件应该将服务器指向我的自定义应用程序?我在这里想念什么?
编辑:我也收到此错误:
ModuleNotFoundError: No module named 'ebdjango/wsgi'
我的文件结构有问题吗?
编辑 2:我忘记在我的帖子中包含init .py 文件,请参阅 Ben 的评论。
解决方案
我遇到过同样的问题。这是因为 Amazon Linux 2 机器映像。它的配置文件与旧版本的配置文件不兼容。请参阅:https ://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html 。我最终使用了旧版本,因为文档说:
如果您使用的是 Beta 版的 Amazon Linux 2 平台版本进行评估,请不要投入生产。等到我们发布支持的平台版本。
您可以使用命令行工具使用 Amazon Linux 机器映像(旧版本)创建 Elastic Beanstalk 环境。以下是命令(替换<...>
为您的数据):
eb init -p python-3.6 <ApplicationName> --region <Region>
eb create <EnvironmentName> --elb-type application --platform "64bit Amazon Linux 2018.03 v2.9.10 running Python 3.6"
更新 2020-06-02
正如我之前提到的,这个问题是由 Amazon Linux 2 平台引起的,因为它使用 Gunicorn,它的 WSGI 语法与以前的版本不同。WSGIPath
必须ebdjango.wsgi:application
是。请参阅https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-container.html#python-namespaces。
推荐阅读
- python - 从字典中拉出多个数组并用 numpy 堆叠它们的 Pythonic 方法
- reactjs - 如何将 Bpmn-js 的 Modeler 集成到 React 中
- python - Selenium webdriver错误Chrome无法启动
- c++11 - 如何识别或避免空的 boost::function 为 std::function
- angular - mat-select 多个 rtl 方向显示反向选中项文本
- apostrophe-cms - POST 到 /poll-notifications/ 在应用程序重新启动后立即花费很长时间
- tornado - 结合异步和龙卷风
- stream - 流分析从历史上平均保持 1 年
- node.js - 如何禁用存储在 mongodB 数据库中的信息不显示在前端但不应该从数据库中删除
- html - 在角度应用程序中,父级悬停在父级的下一个兄弟之后,显示绝对定位的 div(宽度大于父级)