如何配置 Rails 5.2.1 服务器监听所有接口? [英] How to configure Rails 5.2.1 server listen on all interfaces?

查看:55
本文介绍了如何配置 Rails 5.2.1 服务器监听所有接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 RoR 和学习还很陌生,所以如果我有后续问题,请耐心等待.我们的 Rails (v 5.0.2) 应用程序配置为在 config/boot.rb 中使用此配置侦听所有接口:

I'm still fairly new to RoR and learning so please bear with me if I have follow-up questions. Our Rails (v 5.0.2) app was configured to listen on all interfaces with this configuration in config/boot.rb:

require 'rails/commands/server'
module Rails
  class Server
    def default_options
      # make rails listen on all interfaces (accept connections from any ip)
      super.merge(Host: '0.0.0.0', Port: 1234)
    end
  end
end

我最近将 Rails 从 5.0.2 升级到 5.2.1,当我运行 rails s 时,我得到:

I recently upgraded Rails from 5.0.2 to 5.2.1 and when I run rails s, I get:

/Users/aum/rails_app/config/boot.rb:5:in `require': cannot load such file -- rails/commands/server (LoadError)
    from /Users/aum/rails_app/config/boot.rb:5:in `<top (required)>'
    from bin/rails:8:in `require_relative'
    from bin/rails:8:in `<main>'

所以我将 'require' 更新为 rails/commands/server/server_command 现在我得到了

So I updated the 'require' to rails/commands/server/server_command and now I get

rails s
/Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:110:in `<module:Command>': uninitialized constant Rails::Command::Base (NameError)
Did you mean?  Base64
  from /Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:109:in `<module:Rails>'
  from /Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:11:in `<top (required)>'
  from /Users/aum/rails_app/config/boot.rb:5:in `require'
  from /Users/aum/rails_app/config/boot.rb:5:in `<top (required)>'
  from bin/rails:8:in `require_relative'
  from bin/rails:8:in `<main>'

我不确定如何/在何处指定 Rails 5.2.1 中的主机和端口,因为这里的 default_options 定义也发生了变化:https://github.com/rails/rails/blob/master/railties/lib/rails/commands/server/server_command.rb#L68

I'm not sure how/where to specify the host and port in Rails 5.2.1 since the default_options definitions has also changed here: https://github.com/rails/rails/blob/master/railties/lib/rails/commands/server/server_command.rb#L68

注意:我可以使用 rails s -b 0.0.0.0 -p 1234 启动服务器,但这不是我想要做的.

NOTE: I can start the server with rails s -b 0.0.0.0 -p 1234 but that is not what I'm trying to do.

预先感谢您的帮助!

推荐答案

假设您正在使用 puma,这是 Rails 5 的默认 HTTP 服务器,绑定选项定义在 config/puma.rb:

Assuming you're using puma, which is the default HTTP server for Rails 5, the binding options are defined in config/puma.rb:

bind 'tcp://0.0.0.0:3000'

这篇关于如何配置 Rails 5.2.1 服务器监听所有接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆