How can i fix 502 Bad Gateway NGINX error while deploying a django app on AWSEB command line?

Viewed 5078
3 Answers

It's true that Python 3.7+ on Amazon Linux 2 platform needs gunicorn. In my case I only needed to pip install gunicorn and add it in requirements.txt. I did not need to edit the setting.py file. Also my django.config looks like below:

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

Reference: AWS documentation on deploying Django with Beanstalk

For Python 3.7 Amazon Linux 2 platform for ebs firstly install gunicorn then add it to your requirements.txt and edit the django.config file to

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 deploy
eb open

Check the file web.stdout.log; it should tell you what the error was. You can access this by downloading the EB logs, or by running eb ssh and finding it in the /var/log/ directory.

Related