简体   繁体   English

AWS beantalk + Django:502 错误网关 - ModuleNotFoundError:没有名为“application”的模块

[英]AWS beanstalk + Django: 502 Bad Gateway - ModuleNotFoundError: No module named 'application'

I'm trying to deploy Django project to Elastic Beanstalk.我正在尝试将 Django 项目部署到 Elastic Beanstalk。 I'm following their guide: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html But after eb open all pages return "502 Bad Gateway".我正在关注他们的指南: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html但是在eb open所有页面后返回“502 Bad Gateway”。

My AWS admin shows django environment as "Degraded".我的 AWS 管理员将 django 环境显示为“已降级”。 Please see the screenshot:请看截图: 在此处输入图像描述

My logs, seems like something with "ModuleNotFoundError: No module named 'application'":我的日志似乎带有“ModuleNotFoundError:没有名为‘application’的模块”:

----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Jan 27 19:30:21 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jan 27 19:30:21 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jan 27 19:30:21 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jan 27 19:30:21 ip-172-31-32-137 web: ModuleNotFoundError: No module named 'application'
Jan 27 19:30:21 ip-172-31-32-137 web: [2021-01-27 19:30:21 +0000] [3483] [INFO] Worker exiting (pid: 3483)
Jan 27 19:30:21 ip-172-31-32-137 web: [2021-01-27 19:30:21 +0000] [3476] [INFO] Shutting down: Master
Jan 27 19:30:21 ip-172-31-32-137 web: [2021-01-27 19:30:21 +0000] [3476] [INFO] Reason: Worker failed to boot.
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3488] [INFO] Starting gunicorn 20.0.4
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3488] [INFO] Listening at: http://127.0.0.1:8000 (3488)
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3488] [INFO] Using worker: threads
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3495] [INFO] Booting worker with pid: 3495
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3495] [ERROR] Exception in worker process
Jan 27 19:30:22 ip-172-31-32-137 web: Traceback (most recent call last):
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
Jan 27 19:30:22 ip-172-31-32-137 web: worker.init_process()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
Jan 27 19:30:22 ip-172-31-32-137 web: super().init_process()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
Jan 27 19:30:22 ip-172-31-32-137 web: self.load_wsgi()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
Jan 27 19:30:22 ip-172-31-32-137 web: self.wsgi = self.app.wsgi()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
Jan 27 19:30:22 ip-172-31-32-137 web: self.callable = self.load()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
Jan 27 19:30:22 ip-172-31-32-137 web: return self.load_wsgiapp()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
Jan 27 19:30:22 ip-172-31-32-137 web: return util.import_app(self.app_uri)
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
Jan 27 19:30:22 ip-172-31-32-137 web: mod = importlib.import_module(module)
Jan 27 19:30:22 ip-172-31-32-137 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
Jan 27 19:30:22 ip-172-31-32-137 web: return _bootstrap._gcd_import(name[level:], package, level)
Jan 27 19:30:22 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jan 27 19:30:22 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jan 27 19:30:22 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jan 27 19:30:22 ip-172-31-32-137 web: ModuleNotFoundError: No module named 'application'

I guess there might be problem with wsgi configuration.我猜 wsgi 配置可能有问题。

django.config django.config

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: todo.wsgi

wsgi.py wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo.settings')

application = get_wsgi_application()

config.yaml配置.yaml

branch-defaults:
  main:
    environment: django-env
    group_suffix: null
global:
  application_name: todo
  branch: null
  default_ec2_keyname: null
  default_platform: Python 3.7 running on 64bit Amazon Linux 2
  default_region: eu-north-1
  include_git_submodules: true
  instance_profile: null
  platform_name: null
  platform_version: null
  profile: eb-cli
  repository: null
  sc: git
  workspace_type: Application

Would really appreciate some help!真的很感激一些帮助!

Django configurations are different according to to the Amazon Linux version you prefer to deploy. Django 配置根据您喜欢部署的 Amazon Linux 版本而有所不同。

If you are deploying your application to Amazon Linux 2 ,如果您要将应用程序部署到Amazon Linux 2

.ebextensions/django.conf .ebextensions/django.conf

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: todo.wsgi:application
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: todo.settings
  "aws:elasticbeanstalk:environment:proxy:staticfiles":
    "/static/": "todo/static/"

If you are deploying your application to old version:如果您将应用程序部署到旧版本:

.ebextensions/django.conf .ebextensions/django.conf

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: todo/wsgi
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: todo.settings
  "aws:elasticbeanstalk:environment:proxy:staticfiles":
    "/static/": "todo/static/"

BTW you may want to check the WSGIPath in elastic beanstalk configuration (Container Options) using AWS console:顺便说一句,您可能想使用 AWS 控制台检查弹性 beanstalk 配置(容器选项)中的 WSGIPath:

EBS 容器选项

暂无
暂无

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

相关问题 Elastic Beanstalk Django 应用程序部署 502 错误网关服务器未运行(没有名为“应用程序”的模块) - Elastic Beanstalk Django app deployment 502 Bad Gateway Server not running (No module named: 'application') 将 Django 应用程序部署到 Elastic Beanstalk AWS 502 错误网关 - Deploying a Django application to Elastic Beanstalk AWS 502 Bad Gateway ModuleNotFoundError:没有名为“application”的模块 [部署 Django 到 AWS] - ModuleNotFoundError: No module named 'application' [Deploying Django to AWS] AWS Elastic Beanstalk(Dash plotly 应用程序)- 502 错误网关 - AWS Elastic Beanstalk (Dash plotly app) - 502 Bad Gateway ModuleNotFoundError 出现 502 Bad Gateway 错误:当我将项目部署到谷歌云时,没有名为“flask_wtf”的模块 - 502 Bad Gateway error with ModuleNotFoundError: No module named 'flask_wtf' when i deploy my project to google cloud ModuleNotFoundError:在 AWS Elastic Beanstalk 上部署 Flask 应用程序时没有名为“应用程序”的模块 - ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic Beanstalk ModuleNotFoundError:AWS 中没有名为“应用程序”的模块错误 - ModuleNotFoundError: No module named 'application' error in AWS ModuleNotFoundError:部署到 Elastic Beanstalk 时没有名为“django”的模块 - ModuleNotFoundError: No module named 'django' when deploying to Elastic Beanstalk 部署 Flask 应用程序时,AWS ElasticBeanstalk 中出现 502 Bad Gateway 错误 - 502 Bad Gateway Error in AWS ElasticBeanstalk while deploying Flask Application django视图-502错误的网关 - django views - 502 bad gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM