为什么在端口80上可以看到我的Apache服务器,而在端口3000上却看不到我的Webrick服务器?

问题描述 投票:0回答:1

我在端口80上运行Apache,在端口3000上运行Rails(Webrick)。

使用http://localhosthttp://localhost:3000 ,我可以看到两个服务器。 但是,使用本地IP,我仍然可以看到Apache serv,但是看不到Rails serv。

再次运行cURL,Apache返回200,但是Rails返回curl: (7) Failed to connect to <ip> port 3000: Connection refused

更新资料
我使用-b IP绑定选项和IP重新启动了服务器,但无法再从localhost:3000命中它。 有没有办法绑定到两者?

ruby-on-rails webserver webrick
1个回答
1
投票

传递0.0.0.0作为参数。 那将绑定到所有接口。

如果要永久config/boot.rb可以通过在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

请记住,如果您在共享网络上,这将使其公开可用。

© www.soinside.com 2019 - 2024. All rights reserved.