I'm running django with apache and I'm getting the following error in my apache error.log:
django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'example.com'. You may need to add 'example.com' to ALLOWED_HOSTS., referer: http://example.com/
In my settings.py I have:
ALLOWED_HOSTS = ['*']
This should allow any host shouldn't it?
Edit: After some more investigating I've found out that no matter what I set ALLOWED_HOSTS to, it always results in the above error. I can reach the website just fine when I'm using the local IP address of the server. The only thing that's not working is the remote URL.
I finally found the solution to the problem.
The wsgi.py that's connecting django with apache was overriding the ALLOWED_HOSTS setting in my settings.py.
wsgi has it's own ALLOWED_HOSTS that can be set independently from the django settings. Checking all the possible configuration files was crucial for finding this error.
just add the url to ALLOWED_HOSTS:
ALLOWED_HOSTS = ['ip.ip.ip.ip', '.example.com', '127.0.0.1']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With