7

I have been trying to deploy a Django application on awsebcli. immediately I enter the eb open command I get 502 Bad Gateway NGINX error in return on my web browser. Please I need assistance on how to fix this error, for a better view and understanding my codes screenshots are in the upload links as follows.

settings.py

1

502 Bad Gateway

2

.elasticbeanstalk/config.yml

3

.ebextensions\django.config

4

aswebcli status

5

pip freeze command result

6

I look forward to your kind response. Thank you

Javad
  • 2,033
  • 3
  • 13
  • 23
  • Can you post the log file from eb – Hari Jul 10 '20 at 13:29
  • What about port and name of the starting application python file? THey are set correctly? – Marcin Jul 10 '20 at 23:03
  • 8
    Thanks for your response so far. I finally figured it out. Python 3.7 Amazon Linux 2 platform on elastic beanstalk uses gunicorn as a web server gateway interface (wsgi). It makes the operation of the Django app on the server flexible and faster. I installed gunicorn and added it to the Django installed app under settings.py. i also included it in the requirements.txt for identification. Finally I created a procfile containing "web: gunicorn--bind :8000 --workers 3 --threads 2:.wsgi: application" I deployed into eb and open. NGINX 502 bad gateway error is no more. That settles it. – Emmanuel Oyovwikigho Jul 13 '20 at 14:41
  • 1
    @EmmanuelOyovwikigho i am having the same issue, can you guide more on how you solved it? – Azher Aleem Sep 13 '20 at 18:37
  • You can refer to this answer for help. https://stackoverflow.com/a/67217962/12617787 – Shujaat Sirtaj Apr 22 '21 at 17:20

4 Answers4

2

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.

Josh
  • 2,790
  • 26
  • 30
1

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

Ned_the_Dolphin
  • 154
  • 2
  • 10
  • Kind of weird how the tutorial documentation doesn't state this. Also some tutorials I've found in youtube didn't necessarily did this and still worked out for them. This did the trick if ever some people had trouble with 502 bad gateway – Steven Apr 08 '22 at 06:00
0

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

Sujit Noronha
  • 51
  • 1
  • 4
0

I came across a similar issue using the elastic beanstalk python-3.8 platform and Django 3.2. It's worth noting that the 502 error from nginx will occur with a few different deployment errors (mine were occurring during the manage.py migrate command). Despite fixing the issues suggested in other comments, the 502 error persisted for me.

Ultimately, it was because I was running into some version issues with SQLite and the Amazon Linux 2 platform. I switched to postgres and the issue was fixed.

e2718281
  • 35
  • 1
  • 9