我在生产网站中使用 Django 1.5.1,但由于不允许主机请求,我有大量 500 份报告。我网站的Nginx vhost配置如下:
server {
listen 80;
server_name mywebsite.com.br;
location / {
uwsgi_pass unix:/opt/project/run/brmed_web.sock;
include uwsgi_params;
}
}
我已将允许的主机设置设置settings.py
为:
ALLOWED_HOSTS = ['mywebsite.com.br']
即使它使用我允许的主机完美运行,对于陌生主机,我仍然收到如下错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 92, in get_response
response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py", line 57, in process_request
host = request.get_host()
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 72, in get_host
"Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host)
SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): 108.166.113.25
一些主机,如果不是全部的话,显然是恶意的,因为他们的请求试图欺骗一些 PHP 东西。可以在此链接中找到有关其中一台主机的更多详细信息。
我的问题是,我在允许这些奇怪主机的这些请求通过的 Nginx 配置中缺少什么?仅供参考,我的 Nginx 只有这个配置文件和它的默认配置文件。