can't connect localhost:3000 ruby on rails in vagrant
The solution is running the code below to start your server:
rails s -b 0.0.0.0
I found this solution from another post about same problem.The answerer said 'You'll want to make sure that the server is binded to 0.0.0.0 so that all interfaces can access it."
I hope this post helps people who encounter the same problem :)
You can find the reason in here: http://edgeguides.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
If you want to use rails s
instead of rails s -b 0.0.0.0
, you can edit /config/boot.rb
:
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])require 'rails/commands/server'module Rails class Server alias :default_options_alias :default_options def default_options default_options_alias.merge!(:Host => '0.0.0.0') end endend
Also I have done something like this so that Guard starts this way: guard 'rails', force_run: true, host: '0.0.0.0' do watch('Gemfile.lock') watch(%r{^(config|lib)/.*}) end