Open brucehsu opened 9 years ago
This bit me as well because it breaks docker to bind to localhost. You can revert to the prior bind address with -b0.0.0.0
Hi, I came across the same problem. I was not able to connect to my server from virtual machines (and I wasted so much time to realize that it came from here).
What caused this change ? Rails ? Unicorn ? Unicorn-rails ?
I think this is related to this change in Rails 4.2.0: http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server
@brucehsu is absolutly right. One workaround is to add the following code to your config/boot.rb
require 'rubygems'
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
end
end
@tostasqb Thanks! :+1:
@tostasqb Thank You!!!
Hi I just try to use 'rails server -b 0.0.0.0' but it still cannot work. How should I adjust my firewall? My machine is OS X Yosemite. :)
:+1: - noticed rails was binding to localhost on my vps by default, so specifying -b 0.0.0.0
fixed it for me as well
rails s --binding 0.0.0.0 OR rails s -b 0.0.0.0 OR rails server --binding 0.0.0.0 OR rails server -b 0.0.0.0
Or you can do:
config/boot.rb
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
If you put the default options on config/boot.rb
then all command attributes for rake and rails fail (example: rake -T
or rails g model user
)! So, append this to bin/rails
after line require_relative '../config/boot'
and the code is executed only for the rails server command:
if ARGV.first == 's' || ARGV.first == 'server'
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
end
The bin/rails
file loks like this:
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
# Set default host and port to rails server
if ARGV.first == 's' || ARGV.first == 'server'
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge(Host: '0.0.0.0', Port: 3000)
end
end
end
end
require 'rails/commands'
Did the trick for me. Just in case you're looking for a better solution: -b127.0.0.1
will protect you from the out world :)
After switching to Unicorn on my new project using rails 4.2.0 beta1, I found that I cannot access subdomain via
http://lvh.me
. With further investigation, the problem appears to be related to a binding issue ofunicorn-rails
under 4.2.0 environment.Following tests are done in separate empty rails apps, on my MBPr with OSX 10.9.5, MRI 2.1.3.
Here's the output of
bundle exec rails s
under rails 4.1.6:And here's the one under rails 4.2.0 beta 1:
Seems like 4.2.0 changed its default listening behavior?