为什么我可以在端口 80 上看到我的 Apache 服务器,但在端口 3000 上看不到我的 Webrick 服务器?
Why can I see my Apache server on port 80, but not my Webrick server on port 3000?
我是 运行 Apache 在端口 80 和 Rails (Webrick) 在端口 3000。
使用 http://localhost
和 http://localhost:3000
,我可以看到两个服务器。但是,使用我的本地 IP,我仍然可以看到 Apache 服务,但看不到 Rails 服务。
运行 cURL,Apache returns 200,但是 Rails returns curl: (7) Failed to connect to <ip> port 3000: Connection refused
更新
我使用 -b
IP 绑定选项和我的 IP 重新启动了服务器,但无法再从 localhost:3000 命中它。有没有办法同时绑定两者?
传递 0.0.0.0
作为你的参数。这将绑定到所有接口。
如果你想让这个永久化,你可以通过将以下内容添加到 config/boot.rb
来猴子修补一些 Rails:
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
请记住,如果您在共享网络上,这将使它公开可用。
我是 运行 Apache 在端口 80 和 Rails (Webrick) 在端口 3000。
使用 http://localhost
和 http://localhost:3000
,我可以看到两个服务器。但是,使用我的本地 IP,我仍然可以看到 Apache 服务,但看不到 Rails 服务。
运行 cURL,Apache returns 200,但是 Rails returns curl: (7) Failed to connect to <ip> port 3000: Connection refused
更新
我使用 -b
IP 绑定选项和我的 IP 重新启动了服务器,但无法再从 localhost:3000 命中它。有没有办法同时绑定两者?
传递 0.0.0.0
作为你的参数。这将绑定到所有接口。
如果你想让这个永久化,你可以通过将以下内容添加到 config/boot.rb
来猴子修补一些 Rails:
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
请记住,如果您在共享网络上,这将使它公开可用。