I am trying to deploy my dockerized django app to Elastic, but I keep getting a DisallowedHost exception:
django | Traceback (most recent call last):
django | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
django | response = get_response(request)
django | File "/usr/local/lib/python3.9/site-packages/django/utils/deprecation.py", line 135, in __call__
django | response = self.process_request(request)
django | File "/usr/local/lib/python3.9/site-packages/django/middleware/common.py", line 48, in process_request
django | host = request.get_host()
django | File "/usr/local/lib/python3.9/site-packages/django/http/request.py", line 148, in get_host
django | raise DisallowedHost(msg)
django | django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '10.1.XX.XXX'. You may need to add '10.1.XX.XXX' to ALLOWED_HOSTS.
I am not sure what the ip relates to but it is different everytime I try to deploy.
my settings:
ALLOWED_HOSTS = ['my.domain', 'xxx.ap-southeast-2.elasticbeanstalk.com']
I have tried adding the EC2 private ip dynamically following this answer (2nd answer not the accepted one): ALLOWED_HOSTS not working in my Django App deployed to Elastic Beanstalk
Similarly this way: Django ALLOWED_HOST setting for Elastic beanstalk instance behind Elastic Load Balancer
I've also tried this answer to create custom middleware: Django ALLOWED_HOSTS with ELB HealthCheck
When I set allowed hosts to '*' it successfully deploys.