在 Elastic Beanstalk 上创建环境时出现 502
502 occurs when creating environment on elastic beanstalk
我在部署我的第一个 Django 项目时遇到问题。
这是我的 config.yml
:
global:
application_name: testapp
branch: null
default_ec2_keyname: aws-eb
default_platform: Python 3.8 running on 64bit Amazon Linux 2
default_region: us-west-2
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application
这是我的 django.config
:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
我关注了this doc。但是在我做了 eb create testapp-env
之后,我得到了 502 错误:
image of the error
如果您需要,我会提供更多信息。预先感谢您的帮助。
这是 web.stdout.log
中的错误:
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
更新
我的 django 项目使用 python-socketio,这是我的 wsgi.py:
from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')
django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)
我收到另一个错误:
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
您需要设置DJANGO_SETTINGS_MODULE
环境变量:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "djangoproject.settings"
您还需要编辑 wsgi.py
文件,因为您在 Django 设置之前访问应用程序:
import django
django.setup()
from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')
django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)
我在部署我的第一个 Django 项目时遇到问题。
这是我的 config.yml
:
global:
application_name: testapp
branch: null
default_ec2_keyname: aws-eb
default_platform: Python 3.8 running on 64bit Amazon Linux 2
default_region: us-west-2
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application
这是我的 django.config
:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
我关注了this doc。但是在我做了 eb create testapp-env
之后,我得到了 502 错误:
image of the error
如果您需要,我会提供更多信息。预先感谢您的帮助。
这是 web.stdout.log
中的错误:
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
更新
我的 django 项目使用 python-socketio,这是我的 wsgi.py:
from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')
django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)
我收到另一个错误:
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
您需要设置DJANGO_SETTINGS_MODULE
环境变量:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "djangoproject.settings"
您还需要编辑 wsgi.py
文件,因为您在 Django 设置之前访问应用程序:
import django
django.setup()
from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')
django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)