使用 AWS Elasticbeanstalk 部署 Django 应用程序时出现 WSGIPath 错误
Posted
技术标签:
【中文标题】使用 AWS Elasticbeanstalk 部署 Django 应用程序时出现 WSGIPath 错误【英文标题】:WSGIPath Error while Deploying Django App using AWS Elasticbeanstalk 【发布时间】:2016-11-14 10:26:35 【问题描述】:我正在尝试使用 Elastic Beanstalks 在 AWS 上部署我的 Django 项目。我已经为 WSGIPath 尝试了多个值更改。 但每次,我都会遇到同样的错误:
从 ubuntu 终端运行“eb create”时:
错误日志(来自 Eb 日志):
-------------------------------------
/var/log/httpd/error_log
-------------------------------------
mod_wsgi (pid=3005): Target WSGI script '/opt/python/current/app/myapp/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=3005): Exception occurred processing WSGI script '/opt/python/current/app/myapp/wsgi.py'.
Traceback (most recent call last):
File "/opt/python/current/app/myapp/wsgi.py", line 24, in <module>
application = get_wsgi_application()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/opt/python/run/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/opt/python/run/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
有人能解释一下这条路是怎么走的以及如何纠正吗?
我的项目结构:
.
├── .ebextensions
│ ├── myapp.config
├── .elasticbeanstalk
│ ├── config.yml
├── db.sqlite3
├── manage.py
├── media
├── abc
│ ├── admin.py
│ ├── apps.py
│ ├── constants.py
│ ├── __init__.py
│ │ └── __init__.py
│ ├── models.py
│ ├── test1_form.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── requirements.txt
├── static
├── templates
└── myapp
├── constants.py
├── test1_form.py
├── __init__.py
├── registration_form.py
├── settings.py
├── urls.py
├── views.py
└── wsgi.py
myapp.config 文件:
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: "myapp/wsgi.py"
config.yml 文件
branch-defaults:
master:
environment: abc-dev
group_suffix: null
global:
application_name: abc
default_ec2_keyname: abc_eb_key
default_platform: Python 2.7
default_region: us-east-1
profile: eb-cli
sc: git
settings.py 文件:
WSGI_APPLICATION = 'myapp.wsgi.application'
myapp/wsgi.py 文件:
import os, sys, inspect
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
application = get_wsgi_application()
【问题讨论】:
有什么建议吗? 你解决了吗?我有同样的错误 @Vlad,是的,我解决了这个问题。我在答案中添加了更新的 myapp.config 文件。看看这是否适合你。如果没有,请分享您的项目结构、配置文件和错误日志(eb logs > logs.txt)。 【参考方案1】:更新了 myapp.config 文件,该文件有效:
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: "myapp/wsgi.py"
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
【讨论】:
以上是关于使用 AWS Elasticbeanstalk 部署 Django 应用程序时出现 WSGIPath 错误的主要内容,如果未能解决你的问题,请参考以下文章
在 AWS 上使用 ElastiCache 和 ElasticBeanstalk 配置 Redis
为啥要为 Docker 使用 AWS ECS 与 ElasticBeanstalk?
AWS-ElasticBeanstalk:在哪里可以找到 Beanstalk 自动创建的域名指向啥?