Allowed Host Setting for Django on EC2
Asked Answered
F

1

8

I just deployed to an Amazon EC2 bitnami djnago stack and I'm having trouble with the ALLOWED_HOSTS setting in the settings.py file. I am not sure what hostname to use or where to find it. I have tried internal IP, external IP, localhost, domain name. The only thing that gets the 500 error pages to stop, is:

ALLOWED_HOSTS = ['*']

But, this is a security issue. What am I missing?

Footwear answered 9/5, 2013 at 16:39 Comment(2)
Set it to ['.yourdomain.com']. Where yourdomain.com is the domain name you're using to access it.Lockridge
that did it! thanks. i had tried ['www.domain.com'] before and that didn't work. Why does the www screw it up?Footwear
L
15

Set it to -

ALLOWED_HOSTS = [
  '.yourdomain.com'
]

Where yourdomain.com is the domain name you're using to access it.

The documentation says -

Values in this list can be fully qualified names (e.g. 'www.example.com'), in which case they will be matched against the request’s Host header exactly (case-insensitive, not including port). A value beginning with a period can be used as a subdomain wildcard: '.example.com' will match example.com, www.example.com, and any other subdomain of example.com.

When you set it to www.yourdomain.com, there must have been some request to another subdomain, other than www. Which caused the trouble. I cannot say exactly because I don't have that much information.

Lockridge answered 9/5, 2013 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.