【问题标题】:Why can I see my Apache server on port 80, but not my Webrick server on port 3000?为什么我可以在端口 80 上看到我的 Apache 服务器,但在端口 3000 上看不到我的 Webrick 服务器?
【发布时间】:2016-01-23 01:31:22
【问题描述】:

我在端口 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】:

    传递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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-27
      • 2019-11-05
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多