0

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…I'm 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.

Any thoughts on why this is happening?

Used References:

Kiran Parajuli
  • 820
  • 6
  • 14
andrewhunter
  • 183
  • 9
  • Can you show your Route 53 config for example.com and www.example.com? – Arun T Jun 14 '23 at 05:27
  • I screwed up and had 4 w's in my wwww.example.com...i guess 4 w's is hard to distinguish visually from 3 w's, because I looked at that multiple times to confirm that i didn't have a typo. I'm going to delete this post. – andrewhunter Jun 14 '23 at 14:27
  • Glad you got it solved – Arun T Jun 14 '23 at 17:48

0 Answers0