官网:How nginx processes a request
翻译部分: How to prevent processing requests with undefined server names
开始!
If requests without the “Host” header field should not be allowed, a server that just drops the requests can be defined:
如果不允许请求没有host头字段 ,可以定义一个只删除请求的服务器,如下:
server { listen 80; server_name ""; return 444; }
Here, the server name is set to an empty string that will match requests without the “Host” header field, and a special nginx’s non-standard code 444 is returned that closes the connection.
这里,server_name被设置为"" (一个空字符串)的服务器将匹配没有带host头字段的请求,且返回一个特殊的nginx的非标准状态码444来关闭链接。
Since version 0.8.48, this is the default setting for the server name, so the
server_name ""
can be omitted. In earlier versions, the machine’s
hostname was used as a default server name.
自0.8.48版本以来,这是server_name的默认配置,所以server_name ""可以被忽略。在更早的版本中,机器的主机名被用作默认的服务器名。