curl无法连接到localhost端口80 [英] curl Failed to connect to localhost port 80
问题描述
我的主机文件映射 127.0.0.1
到 localhost
。
My hosts file maps 127.0.0.1
to localhost
.
$ 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
在我的hosts文件中我有
In my hosts file I have
127.0.0.1 localhost
curl
命令无法识别 / etc / hosts
中的条目。有人可以解释为什么?
It appears that curl
command fails to recognize entries in /etc/hosts
. Can someone explain why?
更新:我还没有尝试这个,但我已经发现你可以配置 nginx响应ipv4和ipv6
update: i've yet to try this but i've discoved you can configure nginx to respond to ipv4 and ipv6
推荐答案
由于您的主机文件中有 :: 1 localhost
行,因此curl似乎尝试使用IPv6联系您的本地Web服务器。
Since you have a ::1 localhost
line in your hosts file, it would seem that curl is attempting to use IPv6 to contact your local web server.
由于网络服务器未在IPv6上侦听,因此连接失败。
Since the web server is not listening on IPv6, the connection fails.
您可以尝试使用 - ipv4
选项 curl
,当两者都可用时,应强制IPv4连接。
You could try to use the --ipv4
option to curl
, which should force an IPv4 connection when both are available.
这篇关于curl无法连接到localhost端口80的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!