Curl以 "curl: (6) 无法解析主机:HTTP"

问题描述 投票:0回答:1

我一直在关注一个关于如何用nginx编译modsecurity的博客。博客. 我试图验证一切工作与创建文件。/etc/nginx/conf.d/echo.conf 其中包含。

    server {
       listen localhost:8085;
       location / {
            default_type text/plain;
            return 200 "Thank you for requesting ${request_uri}\n";
           }
    }

我在cmd中运行了以下内容

    sudo nginx -s reload
    curl -D - http://localhost:8085 HTTP/1.1 200 OK

我得到了

HTTP/1.1 200 OK
Server: nginx/1.19.0
Date: Wed, 10 Jun 2020 19:31:08 GMT
Content-Type: text/plain
Content-Length: 27
Connection: keep-alive

Thank you for requesting /
curl: (6) Could not resolve host: HTTP

我已经在这个问题上研究了好几个小时了,也不知道该怎么办。我找到的两个解决方案是

  • 启用IPv6
  • 错误的DNS服务器

我在cmd中用--ipv4运行了这个命令。curl --ipv4 -D - http://localhost:8085 HTTP/1.1 200 OK 我还改变了名字服务器在 /etc/resolv.conf 到8.8.8.8而不是127.0.0.53,这也不行。

有什么好办法吗?

nginx curl mod-security
1个回答
1
投票

这个错误信息的产生是由于你使用的命令语法。当使用 curl 应该通过运行就可以了。

curl -D - http://localhost:8085 

向你定义的webserver发出HTTP请求(localhost 在这种情况下)。) 否则,如果没有额外的选项来解析,它将把额外的参数作为额外的URL来查询,所以它试图查询的是 HTTP 仿佛 http://HTTP,这根本无法工作,至少在你在你的 /etc/hosts 例如:

© www.soinside.com 2019 - 2024. All rights reserved.