502 Bad Gateway nginx/1.20.0 将 django 应用程序部署到 AWS 时出错
502 Bad Gateway nginx/1.20.0 error on django app deployment to AWS
我在 Amazon Linux 2 上部署了该应用程序,它似乎没问题,除了当我尝试访问环境 URL 时出现 502 Bad Gateway
错误的部分。
这是我使用的.ebextensions
:
01_packages.config
packages:
yum:
git: []
postgresql-devel: []
libjpeg-turbo-devel: []
commands:
setuptools:
command: pip install setuptools --upgrade
db-migrate.config
container_commands:
01_migrate:
command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: multitennant_v2.settings
django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: multitennant_v2/wsgi.py
我不确定如何以及在何处定义 nginx 命令。
我访问了 nginx 错误日志,它显示如下:
2021/12/29 05:59:11 [error] 691#691: *43880 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.220, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.8.112"
2021/12/29 05:59:17 [error] 691#691: *43882 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.39.27, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.8.112"
问题出在 djngo.config
文件
而不是上面的应该是:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: multitennant_v2.wsgi:application
我在 Amazon Linux 2 上部署了该应用程序,它似乎没问题,除了当我尝试访问环境 URL 时出现 502 Bad Gateway
错误的部分。
这是我使用的.ebextensions
:
01_packages.config
packages:
yum:
git: []
postgresql-devel: []
libjpeg-turbo-devel: []
commands:
setuptools:
command: pip install setuptools --upgrade
db-migrate.config
container_commands:
01_migrate:
command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: multitennant_v2.settings
django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: multitennant_v2/wsgi.py
我不确定如何以及在何处定义 nginx 命令。
我访问了 nginx 错误日志,它显示如下:
2021/12/29 05:59:11 [error] 691#691: *43880 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.11.220, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.8.112"
2021/12/29 05:59:17 [error] 691#691: *43882 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.39.27, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.8.112"
问题出在 djngo.config
文件
而不是上面的应该是:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: multitennant_v2.wsgi:application