Django应用程序无法在Elastic Beanstalk AWS上启动

时间:2018-04-04 13:35:47

标签: python django python-3.x amazon-web-services elastic-beanstalk

当我在弹性beanstalk上部署我的Django项目时,我收到500内部服务器错误。我已经尝试了所有的东西,EB仪表板看起来很好,健康是完美的,没有提到任何错误。任何人都可以对此有所了解吗?

============= i-03980c0f6a1094e3c ==============
-------------------------------------
/var/log/httpd/error_log
-------------------------------------
[Wed Apr 04 13:15:51.669498 2018] [suexec:notice] [pid 3065] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Apr 04 13:15:51.684578 2018] [http2:warn] [pid 3065] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the 
currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Wed Apr 04 13:15:51.684588 2018] [http2:warn] [pid 3065] AH02951: mod_ssl does not seem to be enabled
[Wed Apr 04 13:15:51.685042 2018] [lbmethod_heartbeat:notice] [pid 3065] AH02282: No slotmem from mod_heartmonitor
[Wed Apr 04 13:15:51.686951 2018] [mpm_prefork:notice] [pid 3065] AH00163: Apache/2.4.27 (Amazon) mod_wsgi/3.5 Python/3.6.2 configured -- resuming normal operations
[Wed Apr 04 13:15:51.686971 2018] [core:notice] [pid 3065] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Wed Apr 04 13:16:13.037691 2018] [mpm_prefork:notice] [pid 3065] AH00169: caught SIGTERM, shutting down
[Wed Apr 04 13:16:14.092208 2018] [suexec:notice] [pid 3287] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Apr 04 13:16:14.107856 2018] [so:warn] [pid 3287] AH01574: module wsgi_module is already loaded, skipping
[Wed Apr 04 13:16:14.110001 2018] [http2:warn] [pid 3287] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the 
currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Wed Apr 04 13:16:14.110011 2018] [http2:warn] [pid 3287] AH02951: mod_ssl does not seem to be enabled
[Wed Apr 04 13:16:14.110578 2018] [lbmethod_heartbeat:notice] [pid 3287] AH02282: No slotmem from mod_heartmonitor
[Wed Apr 04 13:16:14.113943 2018] [mpm_prefork:notice] [pid 3287] AH00163: Apache/2.4.27 (Amazon) mod_wsgi/3.5 Python/3.6.2 configured -- resuming normal operations
[Wed Apr 04 13:16:14.113964 2018] [core:notice] [pid 3287] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Wed Apr 04 13:16:14.142312 2018] [:error] [pid 3292] mod_wsgi (pid=3292): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Wed Apr 04 13:16:14.142341 2018] [:error] [pid 3292] mod_wsgi (pid=3292): Call to 'site.addsitedir()' failed for '/opt/python/run/venv/lib64/python3.6/site-packages:/opt/python/run/venv/lib/python3.6/site-packages'.
[Wed Apr 04 13:16:16.869762 2018] [:error] [pid 3292] mod_wsgi (pid=3292): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Wed Apr 04 13:16:16.869800 2018] [:error] [pid 3292] mod_wsgi (pid=3292): Call to 'site.addsitedir()' failed for '/opt/python/run/venv/lib64/python3.6/site-packages:/opt/python/run/venv/lib/python3.6/site-packages'.
[Wed Apr 04 13:16:16.870482 2018] [:error] [pid 3292] [remote 127.0.0.1:252] mod_wsgi (pid=3292): Target WSGI script '/opt/python/current/app/testapi/wsgi.py' cannot be loaded as Python module.
[Wed Apr 04 13:16:16.870510 2018] [:error] [pid 3292] [remote 127.0.0.1:252] mod_wsgi (pid=3292): Exception occurred processing WSGI script '/opt/python/current/app/testapi/wsgi.py'.
[Wed Apr 04 13:16:16.870676 2018] [:error] [pid 3292] [remote 127.0.0.1:252] Traceback (most recent call last):
[Wed Apr 04 13:16:16.870699 2018] [:error] [pid 3292] [remote 127.0.0.1:252]   File "/opt/python/current/app/testapi/wsgi.py", line 12, in <module>
[Wed Apr 04 13:16:16.870702 2018] [:error] [pid 3292] [remote 127.0.0.1:252]     from django.core.wsgi import get_wsgi_application
[Wed Apr 04 13:16:16.870716 2018] [:error] [pid 3292] [remote 127.0.0.1:252] ModuleNotFoundError: No module named 'django'
[Wed Apr 04 13:16:17.873718 2018] [:error] [pid 3292] [remote 127.0.0.1:248] mod_wsgi (pid=3292): Target WSGI script '/opt/python/current/app/testapi/wsgi.py' cannot be loaded as Python module.
[Wed Apr 04 13:16:17.873768 2018] [:error] [pid 3292] [remote 127.0.0.1:248] mod_wsgi (pid=3292): Exception occurred processing WSGI script '/opt/python/current/app/testapi/wsgi.py'.
[Wed Apr 04 13:16:17.873855 2018] [:error] [pid 3292] [remote 127.0.0.1:248] Traceback (most recent call last):
[Wed Apr 04 13:16:17.873881 2018] [:error] [pid 3292] [remote 127.0.0.1:248]   File "/opt/python/current/app/testapi/wsgi.py", line 12, in <module>
[Wed Apr 04 13:16:17.873885 2018] [:error] [pid 3292] [remote 127.0.0.1:248]     from django.core.wsgi import get_wsgi_application
[Wed Apr 04 13:16:17.873899 2018] [:error] [pid 3292] [remote 127.0.0.1:248] ModuleNotFoundError: No module named 'django'
[Wed Apr 04 13:16:18.876808 2018] [:error] [pid 3292] [remote 127.0.0.1:2556] mod_wsgi (pid=3292): Target WSGI script '/opt/python/current/app/testapi/wsgi.py' cannot be loaded as Python module.
[Wed Apr 04 13:16:18.876857 2018] [:error] [pid 3292] [remote 127.0.0.1:2556] mod_wsgi (pid=3292): Exception occurred processing WSGI script '/opt/python/current/app/testapi/wsgi.py'.
[Wed Apr 04 13:16:18.876927 2018] [:error] [pid 3292] [remote 127.0.0.1:2556] Traceback (most recent call last):

1 个答案:

答案 0 :(得分:0)

在项目目录中,您应该有一个.elasticbeanstalk文件夹,您必须拥有另一个.ebextensions。如果您没有,请添加它。

然后,您必须创建文件以在EBT为您触发的实例上运行some stuff。例如,添加像10_packages.config这样的文件,这个数字很重要,因为它会保留订单。文件内容是这样的:

# 10_packages.config
# Add the packages needed to run the application and some other tools
packages:
    yum:
        git: []
        postgresql94-devel: []
        gcc: []
        gcc-c++: []
        make: []
        libffi-devel: []
        libmemcached-devel: []
        vim-enhanced: []

然后你需要安装django和你的应用程序所需的所有软件包。创建一个名为20_pip_requirements.config

的文件
# 20_pip_requirements.config
# Update pip in the venv
commands:
  01_upgrade_pip_for_venv:
    command: "sudo /opt/python/run/venv/bin/pip install --upgrade pip"

最终,您必须迁移数据库,这必须只运行一次。让我们触发另一个文件30_migrate.config

# 30_migrate.config
container_commands:
  01_migrate_database:
        command: "./manage.py migrate"
        leader_only: true

这只是一个例子,但是让你知道你必须做什么。

阅读docs了解详情。