我有一个 django 应用程序,我试图将其部署到 aws elastic beanstalk 中,但我从 nginx 收到 502 错误,我安装了 Gunicorn 并列在我的 requests.txt 文件中。
检查日志我看到以下内容:
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3510] [INFO] Starting gunicorn 20.1.0
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3510] [INFO] Listening at: http://127.0.0.1:8000 (3510)
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3510] [INFO] Using worker: gthread
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3516] [INFO] Booting worker with pid: 3516
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3516] [ERROR] Exception in worker process
Nov 17 20:35:22 ip-172-31-12-36 web: Traceback (most recent call last):
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
Nov 17 20:35:22 ip-172-31-12-36 web: worker.init_process()
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
Nov 17 20:35:22 ip-172-31-12-36 web: super().init_process()
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
Nov 17 20:35:22 ip-172-31-12-36 web: self.load_wsgi()
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
Nov 17 20:35:22 ip-172-31-12-36 web: self.wsgi = self.app.wsgi()
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
Nov 17 20:35:22 ip-172-31-12-36 web: self.callable = self.load()
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
Nov 17 20:35:22 ip-172-31-12-36 web: return self.load_wsgiapp()
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
Nov 17 20:35:22 ip-172-31-12-36 web: return util.import_app(self.app_uri)
Nov 17 20:35:22 ip-172-31-12-36 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
Nov 17 20:35:22 ip-172-31-12-36 web: mod = importlib.import_module(module)
Nov 17 20:35:22 ip-172-31-12-36 web: File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
Nov 17 20:35:22 ip-172-31-12-36 web: return _bootstrap._gcd_import(name[level:], package, level)
Nov 17 20:35:22 ip-172-31-12-36 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Nov 17 20:35:22 ip-172-31-12-36 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Nov 17 20:35:22 ip-172-31-12-36 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Nov 17 20:35:22 ip-172-31-12-36 web: ModuleNotFoundError: No module named 'application'
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3516] [INFO] Worker exiting (pid: 3516)
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3510] [INFO] Shutting down: Master
Nov 17 20:35:22 ip-172-31-12-36 web: [2021-11-17 20:35:22 +0000] [3510] [INFO] Reason: Worker failed to boot.
有人知道如何解决这个问题吗?
这篇文章对我有用。 https://stackoverflow.com/a/75645678/21749181
专门添加一个空白的.ebignore文件
我的 django.config 看起来像这样
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: <app name>.settings
PYTHONPATH: /var/app/current:$PYTHONPATH
aws:elasticbeanstalk:container:python:
WSGIPath: <app name>.wsgi:application
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static