I’m trying to deploy my Django app on elastic beanstalk. It is saying that it is deployed, but the health immediately turns red and I see "502 Bad Gateway / Nginx" when I try to go to the site. I know there are other answers to this question on stack overflow, but I am still stuck.
In my logs I see web: ModuleNotFoundError: No module named 'mysite.wsgi'
.
In my file repos/mydjangoproject/mysite/.ebextensions/django.config
I have
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "core.settings"
PYTHONPATH: "/var/app/current:$PYTHONPATH"
aws:elasticbeanstalk:container:python:
WSGIPath: mysite.wsgi:application
And I have a file:
repos/mydjangoproject/mysite/mysite/wsgi.py
Which contains
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()
I also am seeing these errors
2022/07/04 01:57:50 [error] 3507#3507: *536 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.22.27, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "44.241.154.93"
2022/07/04 01:57:50 [error] 3507#3507: *536 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.22.27, server: , request: "GET /blog/wp-includes/wlwmanifest.xml HTTP/1.1", upstream: "http://127.0.0.1:8000/blog/wp-includes/wlwmanifest.xml", host: "44.241.154.93"
I have gunicorn installed and in my requirements.txt.
I am using ‘Python 3.8 running on 64bit Amazon Linux 2/3.3.14’, Django==4.0.1, and gunicorn==20.1.0.
Any thoughts on what I might be doing wrong would be appreciated!
2
Answers
Is your django version compatible with the Python version on Elastic Beanstalk? In their installation example they use
pip install django==2.2
Scroll to step 3. Let me know if this helped before I look for other errors.
Python 3.8, Django 4.1.4 works with: