ALLOWED_HOSTS and Django

自古美人都是妖i 提交于 2021-01-27 04:07:11

问题


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?


回答1:


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.




回答2:


As I said in comments :

First option :

You have to write : ALLOWED_HOSTS=["bla-bla.com", "localhost", "127.0.0.1"] in settings.py file

Then, you just have to restart your server with :

sudo reboot

Or easily reload or restart apache2 service

service apache2 reload or service apache2 restart

It should work now ;)




回答3:


ALLOWED_HOSTS = [
    '127.0.0.1',
    'localhost',
    'bla-bla',
]


来源:https://stackoverflow.com/questions/45194182/allowed-hosts-and-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!