How to fix 502 Bad Gateway NGINX error while deploying a django app on AWSEB command line?
Asked Answered
E

5

8

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

Excurvate answered 10/7, 2020 at 13:0 Comment(5)
Can you post the log file from ebSelfmoving
What about port and name of the starting application python file? THey are set correctly?Landri
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:<appname>.wsgi: application" I deployed into eb and open. NGINX 502 bad gateway error is no more. That settles it.Excurvate
@EmmanuelOyovwikigho i am having the same issue, can you guide more on how you solved it?Camass
You can refer to this answer for help. https://mcmap.net/q/1468594/-error-on-eb-aws-502-bad-gateway-nginx-1-18-0Beatitude
P
5

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.

Pathy answered 9/3, 2022 at 18:25 Comment(0)
S
2

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

Sturgis answered 3/7, 2021 at 5:40 Comment(1)
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 gatewayJung
B
1

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

Boxboard answered 29/5, 2021 at 4:44 Comment(0)
G
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.

Gil answered 6/2, 2023 at 20:43 Comment(0)
R
0

In my case the below step worked.

  1. Run eb config command.
  2. It opens up the file. Look for aws:elasticbeanstalk:container:python:
  3. If it has application, change it to elernet.wsgi:application
Ruelu answered 12/3 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.