简体   繁体   English

Elastic Beanstalk Django 应用程序部署 502 错误网关服务器未运行(没有名为“应用程序”的模块)

[英]Elastic Beanstalk Django app deployment 502 Bad Gateway Server not running (No module named: 'application')

I deployed an application to AWS via Elastic Beanstalk, and when I finished pushing the project to aws (Elastic Beanstalk), I am faced with perpetual 502 Bad Gateway errors (probably because the Django app server never actually started, and Nginx can't proxy us through).我通过 Elastic Beanstalk 将应用程序部署到 AWS,当我完成将项目推送到 aws(Elastic Beanstalk)时,我面临永久 502 Bad Gateway 错误(可能是因为 Django 应用程序服务器从未真正启动,并且 Nginx 无法代理我们通过)。 Looking at the logs, I found a weird error that seems very specific, and erroneous.查看日志,我发现了一个奇怪的错误,看起来非常具体且错误。 It looks like so:它看起来像这样:

 Traceback (most recent call last):
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
Dec 13 09:00:10 ip-172-31-35-65 web: worker.init_process()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
Dec 13 09:00:10 ip-172-31-35-65 web: super().init_process()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
Dec 13 09:00:10 ip-172-31-35-65 web: self.load_wsgi()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
Dec 13 09:00:10 ip-172-31-35-65 web: self.wsgi = self.app.wsgi()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
Dec 13 09:00:10 ip-172-31-35-65 web: self.callable = self.load()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
Dec 13 09:00:10 ip-172-31-35-65 web: return self.load_wsgiapp()
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
Dec 13 09:00:10 ip-172-31-35-65 web: return util.import_app(self.app_uri)
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/site-packages/gunicorn/util.py", line 359, in import_app
Dec 13 09:00:10 ip-172-31-35-65 web: mod = importlib.import_module(module)
Dec 13 09:00:10 ip-172-31-35-65 web: File "/.../python3.8/importlib/__init__.py", line 127, in import_module
Dec 13 09:00:10 ip-172-31-35-65 web: return _bootstrap._gcd_import(name[level:], package, level)
Dec 13 09:00:10 ip-172-31-35-65 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Dec 13 09:00:10 ip-172-31-35-65 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Dec 13 09:00:10 ip-172-31-35-65 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Dec 13 09:00:10 ip-172-31-35-65 web: ModuleNotFoundError: No module named 'application'
Dec 13 09:00:10 ip-172-31-35-65 web: [2021-12-13 09:00:10 +0000] [8602] [INFO] Worker exiting (pid: 8602)
Dec 13 09:00:10 ip-172-31-35-65 web: [2021-12-13 09:00:10 +0000] [8596] [INFO] Shutting down: Master
Dec 13 09:00:10 ip-172-31-35-65 web: [2021-12-13 09:00:10 +0000] [8596] [INFO] Reason: Worker failed to boot

Previously this application was working properly before this push (and it works perfectly fine in a virtual environment localhost).以前,此应用程序在此推送之前可以正常工作(并且在虚拟环境 localhost 中可以正常工作)。 However now it seems to give this weird No module named 'application' error.但是现在它似乎给出了这个奇怪的 No module named 'application' 错误。 I've run 'pip3 freeze > requirements.txt', I've tried to reboot the instance and deploy again (to no avail).我已经运行了“pip3 freeze > requirements.txt”,我尝试重新启动实例并再次部署(无济于事)。 If it helps the project is using django-crontab (the only reason I mention this is because I recently added it, and now this weird problem is arising).如果它有助于项目使用 django-crontab (我提到这一点的唯一原因是因为我最近添加了它,现在出现了这个奇怪的问题)。 Also if I go back to previous version the app works again.... the wsgi file is unchanged, and the config file only had 4 lines injected (2 commands).此外,如果我 go 回到以前的版本,应用程序再次工作.... wsgi 文件未更改,配置文件仅注入 4 行(2 个命令)。 So I'm very confused where this error is coming from.所以我很困惑这个错误来自哪里。

If someone has faced this problem in the past, would you mind letting me know some things you tried to get it working again.如果过去有人遇到过这个问题,你介意让我知道一些你试图让它再次工作的事情吗? Thanks谢谢
In the mean time I will be searching through the configuration files, requirements etc, to figure out what has went wrong.同时,我将搜索配置文件、需求等,找出问题所在。
Note this question is similar to this , however my problem seems to be more isolated, and more detailed.请注意,此问题与类似,但是我的问题似乎更加孤立,更加详细。

The problem I faced was actually was due to a bad PostgreSQL connection .我面临的问题实际上是由于PostgreSQL 连接不良所致。 The connection settings were for development and invalid in production.连接设置用于开发,在生产中无效。 The production connection wasn't working so it was throwing this "erroneous" error.生产连接没有工作,所以它抛出了这个“错误”错误。
If you are getting this error it is likely you have configured production settings wrong (or are still using development settings).如果您收到此错误,则可能是您配置了错误的生产设置(或仍在使用开发设置)。 In my case it was a PostgreSQL problem, in yours it could be some other database or other connecting service.在我的情况下,这是一个 PostgreSQL 问题,在你的情况下,它可能是其他一些数据库或其他连接服务。
check your configurations.检查您的配置。

Bonus points to @Marcin for helping me search for a solution in my case.奖金指向@Marcin 帮助我在我的案例中寻找解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Django 应用程序部署到 Elastic Beanstalk AWS 502 错误网关 - Deploying a Django application to Elastic Beanstalk AWS 502 Bad Gateway AWS Elastic Beanstalk(Dash plotly 应用程序)- 502 错误网关 - AWS Elastic Beanstalk (Dash plotly app) - 502 Bad Gateway Django应用程序已部署到Digitalocean 502 Bad Gateway - Django app deployed to Digitalocean 502 Bad Gateway ModuleNotFoundError:在 AWS Elastic Beanstalk 上部署 Flask 应用程序时没有名为“应用程序”的模块 - ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic Beanstalk 将简单的 web 应用程序部署到 Elastic Beanstalk 时没有名为“应用程序”的模块出错 - No module named 'application' Error while deploying simple web app to Elastic Beanstalk 将Django应用上传到Digitalocean服务器:502错误的网关Nginx / 1.4.6(Ubuntu) - Uploading django app to digitalocean server: 502 bad gateway nginx/1.4.6 (Ubuntu) 无法在 AWS Elastic Beanstalk 上部署 Python Flask 应用程序 | 没有名为“应用程序”的模块 - Python Flask application not deployable on AWS Elastic Beanstalk | No module named 'application' django视图-502错误的网关 - django views - 502 bad gateway 502 网关错误 django + gcloud - 502 bad gateway django + gcloud 502错误的网关错误与运行uwsgi和nginx的python应用程序(centos) - 502 Bad Gateway error with python app running uwsgi and nginx (centos)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM