`rails s` 不再绑定到 10.0.0.4:3000

`rails s` no longer binding to 10.0.0.4:3000

我刚刚在 VirtualBox 运行 OpenBSD 5.7 上设置了 Ruby 2.2.0 和 Rails 4.2,但是为什么我无法连接到 http://10.0.0.4:3000/ rails s?

% rails s
=> Booting Puma
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.0 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000

但是,如果我明确定义 IP 和端口,它确实有效:

% rails s -p 3000 -b 10.0.0.4
=> Booting Puma
=> Rails 4.2.0 application starting in development on http://10.0.0.4:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.0 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://10.0.0.4:3000

但我真的必须这样做吗?

我想我读过(并且您的日志输出证实了这一点)rails s (4.2) 不再绑定到 0.0.0.0(所有接口),而是仅绑定到本地主机。因此,除非有一个新的配置选项使它像以前一样工作,否则您需要 运行 它就像您通过传递 IP 地址一样。您可以传递 0.0.0.0 以获得旧行为。

编辑:是的,请参阅 http://guides.rubyonrails.org/4_2_release_notes.html

的第 3.3 节

Due to a change in Rack, rails server now listens on localhost instead of 0.0.0.0 by default. This should have minimal impact on the standard development workflow as both http://127.0.0.1:3000 and http://localhost:3000 will continue to work as before on your own machine.

However, with this change you will no longer be able to access the Rails server from a different machine, for example if your development environment is in a virtual machine and you would like to access it from the host machine. In such cases, please start the server with rails server -b 0.0.0.0 to restore the old behavior.

If you do this, be sure to configure your firewall properly such that only trusted machines on your network can access your development server.