http://localhost:3000 有效,但 http://127.0.0.1:3000 无效

Lan*_*opp 5 networking web-development hosts localhost macos

我正在本地开发机器上构建 Rails 应用程序。当运行我的本地服务器时,我可以http://localhost:3000毫无问题地访问。但是,当我尝试导航到 时http://127.0.0.1:3000,我得到一个ERR_CONNECTION_REFUSED. 通常,我不会关心这个问题,但是当我尝试使用 访问隧道时ngrok,我收到此错误:

Tunnel <URL> unavailable

Unable to initiate connection to 127.0.0.1:3000. A web server must be running on port 127.0.0.1:3000 to complete the tunnel.
Run Code Online (Sandbox Code Playgroud)

今天早上我全新安装了 OS X,系统上运行的唯一内容就是我的dotfiles readme中的内容。这是我的完整/etc/hosts文件:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
Run Code Online (Sandbox Code Playgroud)

YLe*_*arn 4

在您的主机文件中,您有 IPv4 和 IPv6 解析。如果可用的话,当今大多数操作系统都更喜欢 IPv6。由于 localhost 正在工作,而 127.0.0.1 则不工作,这可能是您的问题。

在这种情况下,我要检查两件事:

  1. 检查服务器/服务是否仅在 IPv6 上运行。如果是这样,请对其进行更改,以便它在 IPv4 和 IPv6 上运行。
  2. 检查防火墙规则,确保它们允许 IPv4 和 IPv6 访问该端口上的本地主机。