Django nginx无效HTTP_HOST标头

时间:2018-02-01 17:18:46

标签: django nginx

我每天都会收到机器人用错误的http_header打我的服务器的电子邮件。我按照这里的步骤: Django ERROR: Invalid HTTP_HOST header: u'/run/myprojectname/gunicorn.sock:'

我认为这样可以解决它。现在的问题是,如果您尝试转到https://35.***.***.***/,我仍然可以让它自动触发无效的HTTP_HOST电子邮件。

我尝试添加listen 443 default_server;

来解决这个问题
server {
    listen 443 default_server;
    listen 80 default_server;
    return 444;
}

但是现在我的网站的合法流量也被阻止了。 这是我的完整配置。非常感谢任何帮助。

server {
    # default server
    listen 80 default_server;
    return 444;
}

server {
    listen 80;
    server_name mysite.com www.mysite.com;

    root /home/ubuntu/web/troopers/;

    location /static/ {
        # if asset versioning is used
        if ($query_string) {
            expires max;
        }
    }

    access_log /home/ubuntu/web/logs/troopersAccess.log;
    error_log  /home/ubuntu/web/logs/troopersError.log;

    location / {
        uwsgi_pass   unix:///home/ubuntu/web/troopersuwsgi.sock;
        include      uwsgi_params;
    }

    # what to serve if upstream is not available or crashes
    error_page 400 /400.html;
    error_page 403 /403.html;
    error_page 404 /404.html;
    error_page 500 502 503 504 /500.html;

    # Compression
    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 5;
    gzip_proxied any;
    gzip_min_length  1100;
    gzip_buffers 16 8k;
    gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    # Some version of IE 6 don't handle compression well on some mime-types,
    # so just disable for them
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    # Set a vary header so downstream proxies don't send cached gzipped
    # content to IE6
    gzip_vary on;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

0 个答案:

没有答案