如何用错误的主机头设置阻止请求?


12

我使用nginx服务我的网站。我想阻止所有与HTTP“主机”标头不符的请求,这些标头与我的网站的域不匹配。

更具体地说,我的nginx.conf包含以下两个服务器块:

server {
    # Redirect from the old domain to the new domain; also redirect
    # from www.newdomain.com to newdomain.com without the "www"
    server_name www.olddomain.com olddomain.com www.newdomain.com;
    listen 80;
    return 301 $scheme://newdomain.com$request_uri;
}

server {
    server_name newdomain.com localhost;
    listen 80;

    # Actual configuration goes here...
}

我想阻止(即“返回”一个444状态代码)主机不是www.olddomain.com,olddomain.com,www.newdomain.com或newdomain.com的任何流量。我怎样才能做到这一点?

Answers:


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.