invalid http_host header django

环境:Centos, Django 1.11.4,

在运行Django Demo时的错误,运行是以监听所有IP的方式

python manage.py runserver 0.0.0.0:8000

报的错是 Invalid HTTP_HOST header Django. You may need to add u’xxx.xxx.com’ to ALLOWED_HOSTS.

解决办法是在Setting.py中,将u’xxx.xxx.com’(你的域名)加入到ALLOWED_HOSTS中,也把本地的ip也加进去。查了下官方文档,说是为了防止HTTP Host header attacks。

ALLOW_HOST = [u’xxx.xxx.com’, ‘localhost’, ‘127.0.0.1’]