我的主机文件将 127.0.0.1
映射到 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
中的条目。有人能解释一下为什么吗?
更新:我还没有尝试过这个方法,但我发现你可以配置nginx来响应IPv4和IPv6
::1 localhost
吗? - Joachim Isaksson::1 localhost
。 - lfender6445