1

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 Answers2

0

Is your django version compatible with the Python version on Elastic Beanstalk? In their installation example they use pip install django==2.2

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

Scroll to step 3. Let me know if this helped before I look for other errors.

  • My Django version is newer than the one they use in their tutorial. I'm running the same python version (3.8) on my computer and Django is running fine. This says that Django 4.0 supports python 3.8 also: https://docs.djangoproject.com/en/4.0/releases/4.0/. It is hard to test out downgrading to Django 2.2 because my project uses many features available in Django 4.0 that aren't available in Django 2.2. – user2154589 Jul 04 '22 at 14:03
  • Replace the 'mysite.wsgi:application' with 'mysite/wsgi' for some Python versions running Amazon Linux it should be the slash instead of the dot and without the 'application' – pri2003 Jul 06 '22 at 04:17
  • I tried that as well, though it didn't work. I found a work around which is that if I upload it as a zip file, zipped with this command: zip ../myapp.zip -r * .[^.]*, then it works. I was going through eb deploy with the cli. That still isn't working, but I'm not sure why. I'll just upload via zip file moving forward. – user2154589 Jul 10 '22 at 20:09
0

Python 3.8, Django 4.1.4 works with:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: MYSITE.wsgi:application
Serg Smyk
  • 613
  • 5
  • 11