5

I am using Vagrant to start a Rails app, everything seems right but then, when I create a test app, run rails s and go to localhost:3000 I get a ERR_EMPTY_RESPONSE and nothing is loaded. I get the following output when running rails s:

vagrant@rails-dev-box:~/projects/NewAppName$ rails s
=> Booting WEBrick
=> Rails 4.2.3 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-08-20 11:45:45] INFO  WEBrick 1.3.1
[2015-08-20 11:45:45] INFO  ruby 2.2.1 (2015-02-26) [i686-linux]
[2015-08-20 11:45:45] INFO  WEBrick::HTTPServer#start: pid=12075 port=3000

I already ran rake db:create && rake db:migrate, and created a controller for the root. Anyone has an idea of what can be happening? Thank you.

1 Answers1

13

It's in localhost on vagrant, so you can't connect it. Try rails s -b 0.0.0.0 and then connect to vagrant IP(192.168.50.4:3000, for example).

Igor Pavlov
  • 690
  • 6
  • 10
  • As an extra, this happens because rails doesn't bind by default (since rails 4.2) to all IP addresses on the machine. as Igor said it is only binded to localhost on vagrant and in order to access the server through a custom ip the -b 0.0.0.0 is needed. [Here](http://stackoverflow.com/questions/29083885/what-does-binding-a-rails-server-to-0-0-0-0-buy-you) is question related to this issue. –  Aug 20 '15 at 14:24
  • 2
    as variant, I can advise you using nginx to proxy your rails from localhost to external network. It will proxy the requests from :80 to :3000 or to socket of your server – Igor Pavlov Aug 20 '15 at 14:26
  • You should merely be able to connect on localhost:3000 from the host machine after using -b 0.0.0.0. No need for 192.168.50.4 etc. But as Igor mentioned probably best just setting up nginx – wired00 Mar 11 '17 at 04:07