【问题标题】:How can i fix 502 Bad Gateway NGINX error while deploying a django app on AWSEB command line?在 AWSEB 命令行上部署 django 应用程序时,如何修复 502 Bad Gateway NGINX 错误?
【发布时间】:2020-10-31 05:30:55
【问题描述】:

我一直在尝试在 awsebcli 上部署 django 应用程序。我立即输入 eb open 命令,在我的网络浏览器上得到 502 Bad Gateway NGINX 错误作为回报。请我需要有关如何修复此错误的帮助,以便更好地查看和理解我的代码截图在上传链接中,如下所示..settings.py..502 bad gateway...elasticbeanstalk/config.yml...ebextensions\django.config..@ 987654325@..django_pip_freeze

期待您的友好回复。谢谢

【问题讨论】:

  • 你能从eb发布日志文件吗
  • 启动应用程序python文件的端口和名称呢?它们设置正确吗?
  • 感谢您到目前为止的回复。我终于弄明白了。弹性 beanstalk 上的 Python 3.7 Amazon Linux 2 平台使用 gunicorn 作为 Web 服务器网关接口 (wsgi)。它使 Django 应用程序在服务器上的操作更加灵活和快速。我安装了 gunicorn 并将其添加到 settings.py 下的 Django 安装应用程序中。我还将它包含在 requirements.txt 中以供识别。最后,我创建了一个包含“web: gunicorn--bind:8000 --workers 3 --threads 2:.wsgi: application” 的 procfile,我部署到 eb 中并打开。 NGINX 502 bad gateway 错误不再存在。这样就解决了。
  • @EmmanuelOyovwikigho 我也有同样的问题,你能指导更多关于你是如何解决它的吗?
  • 您可以参考这个答案寻求帮助。 stackoverflow.com/a/67217962/12617787

标签: python django amazon-elastic-beanstalk bad-gateway


【解决方案1】:

对于适用于 ebs 的 Python 3.7 Amazon Linux 2 平台,首先安装 gunicorn,然后将其添加到您的 requirements.txt 并将 django.config 文件编辑为

option_settings: 
  "aws:elasticbeanstalk:application:environment": 
    DJANGO_SETTINGS_MODULE: "elernet.settings" 
    "PYTHONPATH": "/var/app/current:$PYTHONPATH"
  "aws:elasticbeanstalk:container:python": 
    WSGIPath: elernet.wsgi:application 
    NumProcesses: 3 
    NumThreads: 20 

eb 部署
eb打开

【讨论】:

    【解决方案2】:

    Amazon Linux 2 平台上的 Python 3.7+ 确实需要 gunicorn。就我而言,我只需要 pip install gunicorn 并将其添加到 requirements.txt 中。我不需要编辑 setting.py 文件。我的 django.config 也如下所示:

    option_settings:
      aws:elasticbeanstalk:container:python:
        WSGIPath: ebdjango.wsgi:application
    

    参考:AWS documentation on deploying Django with Beanstalk

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-31
      • 2021-06-22
      • 2013-07-16
      • 2021-10-02
      • 2018-08-22
      • 2022-12-18
      • 2019-10-17
      • 1970-01-01
      相关资源
      最近更新 更多