How to fix 502 error when deploying django project as a zip file using elastic beanstalk?

0

I am trying to deploy a Django project as a zip file using ElasticBeanstalk. But I don't know what I am doing wrong. It is a very simple Django project. My file/directory structure for the project is this:

The files that are included in the zip file I upload are all the directories/files in MEMBERS/forening.

django.config contains:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: forening.wsgi:application

requirements.txt contains the output of the command python3 -m pip freeze which is:

asgiref==3.7.2
Django==4.2.8
gunicorn==21.2.0
sqlparse==0.4.4
typing-extensions==4.9.0

The IAM role I use has permission to AdministratorAccess-AWSElasticBeanstalk.

Johan
asked 3 months ago213 views
1 Answer
1

Hello.

Have you checked the application logs or web server logs?
I think there is probably some kind of error log output that can help resolve the cause.

profile picture
EXPERT
answered 3 months ago
  • Hi! I was checking web.stdout.log and it kept saying Invalid HTTP_HOST header: '172.31.31.20'. You may need to add '172.31.31.20' to ALLOWED_HOSTS. So I added that to ALLOWED_HOSTS and then the health went from "severe" to "ok". I don't really know why that fixed the health, do you? I still think there is something wrong even though it says the health is ok. The web.stdout.log is displaying for example: Jan 22 04:31:25 ip-172-31-31-20 web[6877]: Bad Request: / Jan 22 04:43:45 ip-172-31-31-20 web[6877]: Invalid HTTP_HOST header: '13.49.254.128'. You may need to add '13.49.254.128' to ALLOWED_HOSTS. Jan 22 04:43:45 ip-172-31-31-20 web[6877]: Traceback (most recent call last): Jan 22 04:43:45 ip-172-31-31-20 web[6877]: File "/var/app/venv/staging-LQM1lest/lib64/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner Jan 22 04:43:45 ip-172-31-31-20 web[6877]: response = get_response(request) Jan 22 04:43:45 ip-172-31-31-20 web[6877]: File "/var/app/venv/staging-LQM1lest/lib64/python3.9/site-packages/django/utils/deprecation.py", line 133, in call Jan 22 04:43:45 ip-172-31-31-20 web[6877]: response = self.process_request(request) Jan 22 04:43:45 ip-172-31-31-20 web[6877]: File "/var/app/venv/staging-LQM1lest/lib64/python3.9/site-packages/django/middleware/common.py", line 48, in process_request Jan 22 04:43:45 ip-172-31-31-20 web[6877]: host = request.get_host() Jan 22 04:43:45 ip-172-31-

  • I think "ALLOWED_HOSTS" needs to be set to allow VPC CIDR. Probably '172.31.31.20' is a request for ALB health check.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions