【发布时间】:2018-11-11 12:30:39
【问题描述】:
我对 AWS+Django+React 有疑问。我做这个教程https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html。当我写“eb open”时,我遇到了一些麻烦“读取/opt/python/current/app/webpack-stats.json时出错。你确定webpack已经生成了文件并且路径正确吗?”。但是,当我在虚拟环境中本地运行项目时,一切正常。
我的代码:
settings.py
ALLOWED_HOSTS = ['django-decor-env.ffp8hmcfus.us-west-2.elasticbeanstalk.com', '*']
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['core/templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATIC_URL = '/static/'
STATIC_ROOT = "core/staticfiles" - update path.
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'core/static'),
]
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR
# Webpack config
WEBPACK_LOADER = {
'DEFAULT': {
'CACHE': not DEBUG,
'BUNDLE_DIR_NAME': '/', # must end with slash
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
'POLL_INTERVAL': 0.1,
'TIMEOUT': None,
}
}
.exbetensions/python.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: decor/core/wsgi.py
.elasticbeanstalk/django-decor-env.env
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: core/wsgi.py
项目结构Structure
我花了很多时间来解决这个问题......任何有用的建议对我来说都会很棒。
更新:
我决定了 S3 的问题,我在主机上查看了我的文件,发现我的文件 webpack-stats.json 没有推送到 AWS。我上传 webpack-stats.json 并重建我的项目,成功编译,但现在我有新问题Internal Server Error 500
eb logs回:
mod_wsgi (pid=3438): Target WSGI script
'/opt/python/current/app/core/wsgi.py' cannot be loaded as Python module.
[Tue Jun 12 22:43:17.606738 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
mod_wsgi (pid=3438): Exception occurred processing WSGI script
'/opt/python/current/app/core/wsgi.py'.
[Tue Jun 12 22:43:17.606898 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
Traceback (most recent call last):
[Tue Jun 12 22:43:17.606955 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/current/app/core/wsgi.py", line 21, in <module>
[Tue Jun 12 22:43:17.606959 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
application = get_wsgi_application()
[Tue Jun 12 22:43:17.606965 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/run/venv/local/lib/python3.6/site
packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Jun 12 22:43:17.606967 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
django.setup(set_prefix=False)
[Tue Jun 12 22:43:17.606972 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
File "/opt/python/run/venv/local/lib/python3.6/site
packages/django/__init__.py", line 19, in setup
[Tue Jun 12 22:43:17.606974 2018] [:error] [pid 3438] [remote 127.0.0.1:128]
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
我现在做错了什么?谢谢关注。。
【问题讨论】:
-
您没有从日志文件中包含 Python 异常的详细信息。
-
我该怎么做?我是 WSGI 和 Apache 的新手...
-
在异常堆栈跟踪的末尾,有一行给出异常类型及其描述。您只需要从日志文件中获取它。您错过了后续行。
标签: django apache amazon-web-services mod-wsgi