Search code examples
ruby-on-railsvirtualboxpuma

`rails s` no longer binding to 10.0.0.4:3000


I just set up Ruby 2.2.0 with Rails 4.2 on a VirtualBox running OpenBSD 5.7, but why can't I connect to http://10.0.0.4:3000/ when doing 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

It does, however, work if I explicitly define IP and port:

% 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

But should I really have to do all that?


Solution

  • I think I read (and your log output confirms it) that rails s (4.2) no longer binds to 0.0.0.0 (all interfaces) but to localhost only. So, unless there is a new config option to make it work like before you're going to need to run it like you are by passing the IP address. You could pass 0.0.0.0 to get the old behavior.

    EDIT: Yep, see section 3.3 at http://guides.rubyonrails.org/4_2_release_notes.html

    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.