Django无效的HTTP_HOST标题:u' /home/dev/whatever/whatever.sock:'。根据RFC 1034/1035,提供的域名无效

时间:2016-06-08 11:40:07

标签: django nginx https gunicorn

我在一个生产网站中每月发生一次或两次这个错误(??),这个错误已经持续了好几个月。

Invalid HTTP_HOST header: u'/home/dev/whatever/whatever.sock:'. The domain name provided is not valid according to RFC 1034/1035.

Request repr():
<WSGIRequest
path:/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'HTTP_CONNECTION': 'close',
 'HTTP_X_FORWARDED_FOR': '94.XXX.51.168',
 'HTTP_X_FORWARDED_PROTO': 'https',
 'HTTP_X_REAL_IP': '94.XXX.51.168',
 'PATH_INFO': u'/',
 'QUERY_STRING': '',
 'RAW_URI': '/',
 'REMOTE_ADDR': '',
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': u'',
 'SERVER_NAME': '/home/dev/whatever/whatever.sock',
 'SERVER_PORT': '',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SOFTWARE': 'gunicorn/19.4.5',
 'gunicorn.socket': <socket._socketobject object at 0x7fabff8ce4b0>,
 'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7fabff956810>,
 'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>,
 'wsgi.input': <newrelic.api.web_transaction._WSGIInputWrapper object at 0x7fabff956b90>,
 'wsgi.multiprocess': True,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'https',
 'wsgi.version': (1, 0)}>

NGINX配置为仅接受域本身。

upstream django_whatever_server {
  server unix:/home/dev/whatever/whatever.sock fail_timeout=0;
}

proxy_cache_path /var/cache/nginx/whatever/ levels=1:2
    keys_zone=cache_whatever:5m max_size=1g inactive=60m;

server {
    listen 80;
    server_name www.whatever.com.br whatever.com;
    return 301 https://www.whatever.com.br$request_uri;
}

server {
    listen 443 ssl;
    server_name www.whatever.com.br localhost 127.0.0.1;
    keepalive_timeout 70;

    ssl_session_cache shared:SSL:20m;
    ssl_session_timeout 20m;

    ssl_certificate BLAH;
    ssl_certificate_key BLAH;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers BLAH;
    ssl_prefer_server_ciphers on;
    ssl_dhparam BLAH;

    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate BLAH;
    resolver 8.8.8.8 8.8.4.4 valid=300s;


    location / {
        client_max_body_size 12m;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache cache_whatever;
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
        proxy_cache_min_uses 1;
        proxy_cache_lock on;
        proxy_cache_bypass $arg_nocache;
        add_header X-BLAH-Cache-Status $upstream_cache_status;
        proxy_pass http://django_whatever_server;
    }
}

server {
    listen 80 default_server;
    server_name _ "";
    return 444;
}

我有其他网站运行相同的NGINX配置,但HTTPS规则除外。

为什么在地球上HTTP_HOST ==我的套接字文件真实路径?为什么一个月一次/两次? (早先的报告显示bing useragent)

0 个答案:

没有答案