curl 无法连接到本地主机端口 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
在我的主机文件中我有
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 进行联系您的本地网络服务器.
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.
由于 Web 服务器未侦听 IPv6,因此连接失败.
Since the web server is not listening on IPv6, the connection fails.
您可以尝试对 curl
使用 --ipv4
选项,这应该在两者都可用时强制进行 IPv4 连接.
You could try to use the --ipv4
option to curl
, which should force an IPv4 connection when both are available.
这篇关于curl 无法连接到本地主机端口 80的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!