Rails 6 привязывается к 127.0.0.1 по умолчанию? - PullRequest
0 голосов
/ 05 апреля 2020

Я смотрел (хотя и старый) разговор о безопасности по небезопасным рельсам по умолчанию . Мне было интересно, есть ли способ узнать, привязывает ли Rails теперь ip 127.0.0.1, порт 3000 по умолчанию? Когда я раскручиваю рельсы s, я вижу

    ±  |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

Согласно этому довольно старому сообщению о переполнении стека , я попытался добавить следующее в мой boot.rb и получил ошибку о моем Spring версии.

Boot.rb требует 'rails / commands / server'

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.

Я делаю эти шаги, но все равно ошибка.

1 Ответ

1 голос
/ 05 апреля 2020

Вы используете 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 для больше.

...