Jon*_*vat 10 django amazon-web-services amazon-elastic-beanstalk
我正在尝试将我的第一个应用程序部署到 EB,并且正在关注这个 turorial: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'?
Run Code Online (Sandbox Code Playgroud)
我不确定这意味着什么。根据说明,我编辑了 django.config 文件以包含以下文本:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango/wsgi.py
Run Code Online (Sandbox Code Playgroud)
这似乎与我的文件结构相匹配:
- ebdjango
-.ebextensions
- django.config
- .elasticbeanstalk
- ebdjango
_ __init__.py
- settings.py
- urls.py
- wsgi.py
- manage.py
- requirements.txt
Run Code Online (Sandbox Code Playgroud)
所以配置文件设置正确,对吧?
我正在运行 Python 3.7 和 Django 2.2。
我知道 EB 搜索 application.py,我认为配置文件应该将服务器指向我的自定义应用程序?我在这里缺少什么?
编辑:我也收到此错误:
ModuleNotFoundError: No module named 'ebdjango/wsgi'
Run Code Online (Sandbox Code Playgroud)
我的文件结构有问题吗?
编辑 2:我忘记在我的帖子中包含init .py 文件,请参阅 Ben 的评论。
我遇到过同样的问题。这是因为 Amazon Linux 2 机器映像。它的配置文件与旧版本的配置文件不兼容。请参阅:https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html。我最终使用了旧版本,因为文档说:
如果您正在使用处于测试阶段的 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"
Run Code Online (Sandbox Code Playgroud)
更新 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。
小智 4
在 django.config 中更改:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango.wsgi
Run Code Online (Sandbox Code Playgroud)
而在你的
import os
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "ebdjango.settings"
application = get_wsgi_application()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2149 次 |
| 最近记录: |