首页 > 解决方案 > 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 的评论。

标签: djangoamazon-web-servicesamazon-elastic-beanstalk

解决方案


我遇到过同样的问题。这是因为 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


推荐阅读