Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django DisallowedHost error

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.

like image 862
henne90gen Avatar asked Oct 17 '22 22:10

henne90gen


2 Answers

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.

like image 98
henne90gen Avatar answered Oct 30 '22 17:10

henne90gen


just add the url to ALLOWED_HOSTS:

ALLOWED_HOSTS = ['ip.ip.ip.ip', '.example.com', '127.0.0.1']
like image 36
alex Avatar answered Oct 30 '22 18:10

alex