間違ったホストヘッダーセットを持つリクエストをブロックするにはどうすればよいですか?


12

私はnginxを使用してウェブサイトを提供しています。サイトのドメインと一致しないHTTP「Host」ヘッダーを含むすべてのリクエストをブロックしたいと思います。

具体的には、nginx.confに次の2つのサーバーブロックが含まれています。

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...
}

ホストがwww.olddomain.com、olddomain.com、www.newdomain.com、またはnewdomain.comではないトラフィックをブロック(つまり、444ステータスコードを「返す」)したい。これどうやってするの?

回答:


弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.