Nginx 处理没有主机头的请求

Dmi*_*sky 6 nginx

我希望 Nginx 在444处理没有标头的请求时host

我已阅读http://nginx.org/en/docs/http/request_processing.htmlNginx default host when not Defined,其中写着:

"If its value does not match any server name, or the request does not contain
this header field at all, then nginx will route the request to the default server 
for this port."
Run Code Online (Sandbox Code Playgroud)

我已经配置了

server {
  listen 80 default_server;

  # Since version 0.8.48, this is the default setting for the server name, 
  # so the server_name "" can be omitted.
  # server_name "";

  return 444;
}
Run Code Online (Sandbox Code Playgroud)

然后我请求

telnet localhost 80<enter>
GET / HTTP/1.1<enter>
<enter>
Run Code Online (Sandbox Code Playgroud)

并收到一个400,不是444我预期的:

HTTP/1.1 400 Bad Request
Server: nginx/1.2.5
Date: Wed, 28 Nov 2012 21:01:59 GMT
Content-Type: text/html
Content-Length: 172
Connection: close

[body]
Run Code Online (Sandbox Code Playgroud)

当我时也会发生同样的情况

telnet localhost 80<enter>
GET / HTTP/1.1<enter>
Host:<enter>
Run Code Online (Sandbox Code Playgroud)

host当没有提供 header时,如何让 Nginx 访问 444 ?如果服务器认为该请求是错误请求,这是否不可能?

Den*_*ker 6

来自RFC 9112“HTTP/1.1”,“3.2 请求目标”部分

服务器必须使用400 (Bad Request)状态代码响应任何缺少Host标头字段的 HTTP/1.1 请求消息以及任何包含多个Host标头字段行或Host具有无效字段值的标头字段的请求消息。