Rails 6默认绑定到127.0.0.1



我观看了一场关于不安全rails默认值的安全对话(尽管很老(。我想知道是否有一种方法可以判断Rails现在是否绑定到ip 127.0.0.1,默认情况下是3000端口?当我旋转轨道时,我看到

±  |master {1} U:4 ✗| → rails s
=> Booting Puma
=> Rails 6.0.2.2 application starting in development 
=> Run `rails server --help` for more startup options
/Users/pivotal/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/pivotal/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.2/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.3 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://**127.0.0.1**:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop

根据这篇相当古老的Stack溢出文章,我尝试将以下内容添加到我的boot.rb中,但在我的Spring版本中出现了一个错误。

Boot.rb需要"轨道/命令/服务器">

module Rails
class Server
def default_options
super.merge({Port: 10524, Host: '127.0.0.1'})
end
end
end

±  |master {1} U:4 ✗| → rails s
You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).
This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.

我做了这些步骤,但仍然是一个错误。

您使用的是Rails 6,最新版本使用的是puma,您的应用程序也是如此。如果要更改端口,请打开config/puma.rb。在那里你会看到

port        ENV.fetch("PORT") { 3000 }

这条线路使铁路从3000港开始。将其更改为任何其他端口。在您的情况下-

port        ENV.fetch("PORT") { 10524 }

此外,如果您想更改绑定地址,请将port替换为bind

#port        ENV.fetch("PORT") { 3000 }
bind        'tcp://192.168.0.1:10524'

检查https://github.com/puma/puma了解更多信息。

最新更新