Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALLOWED_HOSTS and Django

I tried to launch a Django 1.11 project on production server. When I start the app I see the following error:

Invalid HTTP_HOST header: 'bla-bla-bla.bla-bla-vla.com'. You may need to add u'bla-bla-bla.bla-bla-vla.com' to ALLOWED_HOSTS**

But, host "bla-bla-bla.bla-bla-vla.com" has been added to ALLOWED_HOSTS in settings.py already!

I tried to switch DEBUG from False to True and back. It works fine, then.

What am I doing wrong?

like image 424
Alex Avatar asked Jul 19 '17 14:07

Alex


People also ask

What is Allowed_hosts Django?

ALLOWED_HOSTS. Default: [] (Empty list) A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.

What does Allowed_hosts * mean?

So allowed hosts=[*] means any host is allowed.

What is the use of settings py in Django?

Insights about settings.py file. A Django settings file contains all the configuration of your Django Project. In this article the important points of settings.py file of Django will be discussed. A settings file is just a Python module with module-level variables.

Where is settings py file in Django?

A Django settings file doesn't have to define any settings if it doesn't need to. Each setting has a sensible default value. These defaults live in the module django/conf/global_settings.py .


1 Answers

If Django says:

Invalid HTTP_HOST header: 'bla-bla-bla.bla-bla-vla.com'. You may need to add u'bla-bla-bla.bla-bla-vla.com' to ALLOWED_HOSTS

then you need to add bla-bla-bla.bla-bla-vla.com, literally (or using a dot as a wildcard) to ALLOWED_HOSTS (docs).

Then reload Apache2 (not restart, reload) to verify changes have applied.

like image 179
RompePC Avatar answered Oct 03 '22 18:10

RompePC