Change Rails 4 default binding IP
A couple of days ago, while upgrading company’s platform from Rails 184.108.40.206 to Rails 4.2.7, I noticed that the default IP was bound to localhost. I couldn’t then remotely access the application running on my development virtual machine.
This is due to a change in Rack for security reasons, as explained here.
I had then to figure out a way to access the application from outside the virtual machine, mainly because I usually code and test the application remotely and after some googling I found a nice and clean solution on Stack Overflow:
Open your boot.rb file in your preferred editor and add this snippet to the beginning of the file:
super.merge(Host: '0.0.0.0', Port: 3000)
In this way you will add the “any host” option to Rack default options.
Be careful that, in this way, you could potentially add a security flaw to your application, as well explained on Rack github page:
Running Rack apps on 0.0.0.0 in development mode will allow malicious users on the local network (ex: a Coffee Shop or a Conference) to abuse or potentially exploit the app. Safer to default host to localhost when in development mode.
My advice is to use this workaround only when you’re on a quite secure network such as your company network or a VPN.