I am deploying a django application to AWS elastic beanstalk. I’m having troubles getting a Route 53 hosted domain record to route traffic appropriately, and I think it’s a problem on the application side and not AWS. I have a ticket open with AWS, and in their first response their thinking was that it was probably application problem, but they are still investigating. Was hoping someone here could help me on the Django side.
I have a hosted zone, “example.com” in Route 53. Within the hosted zone I have 4 records, 2 are the NS and SOA records that come with each hosted zone by default. And I created 2 additional “A” records, that
are alias’ to my elastic beanstalk environment. These two records are named “example.com” and “www.example.com”.
In my django application I have added my elastic beanstalk CNAME, “example.com”, and “www.example.com” to the ALLOWED_HOSTS, as follows:
ALLOWED_HOSTS = [‘env-example.eba-emvtkupp.us-west-1.elasticbeanstalk.com’,
‘example.com’,
‘www.example.com’,
‘https://example.com’,
‘https://www.example.com’,]
Note - i added the https versions of the urls as well…im not sure if this is actually necessary.
When i deploy the application to elastic beanstalk everything is normal. I try to access example.com in a browser and it works. I try to access www.example.com from a browser and the browser returns “Bad Request (400)”. I’m not sure why the www.example.com url does not work.
Then, based on the 2 following links I tried updating allowed hosts by removing www.example.com and adding “.example.com” because starting with a period is supposedly a wildcard. Then i redeoployed the application, and now the www.example.com domain works!!! I’m happy it works, but I’m also concerned that having “.example.com” in my allowed hosts could be security issue, and I’d much rather understand why my url was not working when I had “www.example.com” in my allowed hosts.
Anyone seen anything like this?