curl无法连接到本地主机端口80

我的主机文件映射127.0.0.1localhost

 $ curl -I 'localhost' curl: (7) Failed to connect to localhost port 80: Connection refused 

接着

 $ curl -I 127.0.0.1 HTTP/1.1 200 OK Server: nginx/1.2.4 Date: Wed, 09 Apr 2014 04:20:47 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 23 Oct 2012 21:48:34 GMT Connection: keep-alive Accept-Ranges: bytes 

在我的主机文件中

 127.0.0.1 localhost 

似乎curl命令无法识别/etc/hosts条目。 有人能解释为什么吗?

更新:我还没有尝试这一点,但我发现你可以configurationnginx响应ipv4和ipv6

由于您的主机文件中有一个::1 localhost行,似乎curl正试图使用​​IPv6来联系您的本地Web服务器。

由于Web服务器不侦听IPv6,连接失败。

您可以尝试使用--ipv4选项curl ,当两者都可用时应该强制IPv4连接。

如果有其他人遇到这个问题,并且接受的答案不起作用(它不适用于我),请检查是否需要指定80以外的端口。在我的情况下,我在localhost:3000运行一个rails服务器localhost:3000只是使用curl http://localhost ,这是打到端口80。

改变命令curl http://localhost:3000是我的情况。

我也有问题与端口80拒绝连接。我没有使用本地主机。

 curl --data-binary "@/textfile.txt" "http://www.myserver.com/123.php" 

问题是我在我的textfile.txt中有变音符号。

就我而言,文件〜/ .curlrc配置了一个错误的代理。