Looking for a solution how to fix nginx 502 Bad Gateway with Django using Elastic Beanstalk. Django application is correct, locally everything works seamlessly. Problems occurs when I am trying to deploy that application to AWS EC2.
I use AWS PostgreSQL Database.
All environment variables are saved in AWS environments correctly. Have traversed throught all solutions but, nothing helped.
Is it ever possible that some libraries create a conflict that results 502 Bad Gateway?
Using Python 3.11.9
**requitements.txt**
asgiref==3.8.1
boto3==1.34.141
botocore==1.34.141
certifi==2024.7.4
charset-normalizer==3.3.2
colorama==0.4.6
crispy-bootstrap5==2024.2
Django==5.0.6
django-autoslug==1.9.9
django-crispy-forms==2.2
django-environ==0.11.2
django-mathfilters==1.0.0
django-storages==1.14.4
django-utils-six==2.0
djangorestframework==3.15.2
gunicorn==20.1.0
idna==3.7
jmespath==1.0.1
packaging==24.1
phonenumbers==8.13.40
pillow==10.3.0
psycopg2-binary==2.9.9
requests==2.32.3
s3transfer==0.10.2
six==1.16.0
sqlparse==0.5.0
tzdata==2024.1
urllib3==2.2.2
Then
**.ebextensions/django.config**
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ecommerce.wsgi:application
Then
**Procfile**
web: gunicorn ecommerce.wsgi:application --bind 0.0.0.0:8000
Then
**ecommerce/ecommerce/wsgi.py**
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ecommerce.settings")
application = get_wsgi_application()
Then
**.ebignore**
requirements.dev.txt
.pytest_cache/
tests/
.pytest_cache/
*.test.py
test_*.py
*.local
.env
.env.example
.git/
README.md
.prettierignore
.vscode/
.idea/
*.pyc
__pycache__/
.mypy_cache/
.nox/
.coverage
.tox/
.venv/
CMD Output:
>eb logs
Retrieving logs...
===========================
----------------------------------------
/var/log/web.stdout.log
web[2267]: File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/util.py", line 359, in import_app