【问题标题】:How to test a server with a request without the “Host” header field如何使用没有“Host”标头字段的请求测试服务器
【发布时间】:2020-06-06 17:33:19
【问题描述】:

我有一个使用Nginx's 444 to drop connections to undefined hosts的服务器:

server {
    listen      80;
    server_name "";
    return      444; 
}

但我不知道如何测试它是否有效。

这是我在黑暗中尝试过的一些事情:

$ curl -I mysite.com --header 'Host: ""'
HTTP/1.1 301 Moved Permanently

$ curl -I mysite.com --header ''
HTTP/1.1 301 Moved Permanently

我正在尝试获得 444!

这是我的 nginx mysite.conf 文件的相关部分

server {
    listen 80;
    server_name "";
    return 444;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

所以要么我测试错了,要么我测试正确,但丢失的主机头仍然被我的第二个服务器块捕获并重定向。

【问题讨论】:

  • 要检查您的服务器如何处理没有 HTTP Host 标头的请求,您应该通过其 IP 地址访问它))并且您尝试以不正确的方式配置您的服务器,here 是工作示例。
  • 举个例子:假设你的服务器有IP地址1.2.3.4,它服务的域名是example.com,命令curl -I example.comcurl -I 1.2.3.4 --header 'Host: example.com是等价的。
  • 您可以尝试:curl --http1.0 - 但如果 server_name ""; 匹配没有 Host 标头的请求,我会感到惊讶 - 我希望 Nginx 使用 default_server 代替。

标签: nginx curl nginx-config server-name


【解决方案1】:

这适用于 curl 7.47:

curl -I --header Host: mysite.com

请注意,标头选项的参数只是 Host:'Host: ''Host: ""' 不起作用)

最新版本的 curl 可能有一个 --http0.9 选项,可能会得到相同的结果,但我没有测试它。

【讨论】:

    猜你喜欢
    • 2013-05-12
    • 2019-02-04
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    相关资源
    最近更新 更多