为什么本地主机无法在Chrome(OSX)中路由到127.0.0.1? [英] Why won't localhost route to 127.0.0.1 in chrome (OSX)?
问题描述
当我使用node-debug启动脚本时,它会尝试导航到URL localhost/debug?port = 5858,但是找不到在此提供服务的页面.
When I launch a script using node-debug, it attempts to navigate to the URL localhost/debug?port=5858 but does not find a page served there.
如果我将"localhost"更改为127.0.0.1,则一切正常.
If I change the "localhost" to 127.0.0.1 everything works fine.
我可以ping本地主机,并且可以正确解析为127.0.0.1
I can ping localhost and it resolves appropriately to 127.0.0.1
有什么想法吗?
推荐答案
localhost具有一个IPv6地址(:: 1)和一个IPv4地址(127.0.0.1).我的猜测是您的Web服务器仅通过IPv4服务,而chrome则更喜欢IPv6地址.
localhost has an IPv6 address (::1) as well as an IPv4 address (127.0.0.1). My guess is that your web server is only serving over IPv4, and chrome is preferring the IPv6 address.
$ dscacheutil -q host -a name localhost
name: localhost
ipv6_address: ::1
ipv6_address: fe80:1::1
name: localhost
ip_address: 127.0.0.1
$ netstat -an | grep "[.]80 .*LISTEN"
tcp46 0 0 *.80 *.* LISTEN
请注意最后一行中的"tcp46"-这意味着Web服务器正在侦听TCP/IPv4和TCP/IPv6连接.如果运行相同的命令,我怀疑您只会看到"tcp4".
Note the "tcp46" in the last line -- that means the web server is listening for both TCP/IPv4 and TCP/IPv6 connections, If you run the same command, I suspect you'll see just "tcp4".
我不熟悉Node.js,但是此发布似乎暗示您可以使用server.listen(80, '::')
监听两个本地主机地址.或者,您可以为IPv4和IPv6地址创建单独的侦听器,如
I'm not familiar with Node.js, but this posting seems to imply you can listen on both localhost addresses by using server.listen(80, '::')
. Alternately, you could create separate listeners for the IPv4 and IPv6 addresses, as described here.
这篇关于为什么本地主机无法在Chrome(OSX)中路由到127.0.0.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!