I'd like to bind the rails server to 127.0.0.1, instead of 0.0.0.0 so its not accessible when I'm working from coffee shops.
Is there a configuration file where I can specify this option so I don't have to pass the command line switch:
rails server -b 127.0.0.1
?
If you are searching for Rails 5: Answer
In Rails ~> 4.0
you can customize the boot section of the Server class:
In /config/boot.rb
add this lines:
require 'rails/commands/server'
module Rails
class Server
def default_options
super.merge({Port: 10524, Host: '127.0.0.1'})
end
end
end
As already answered on this questions:
How to change Rails 3 server default port in develoment?
How to change the default binding ip of Rails 4.2 development server?
You can make a bash script to just run the command by default:
#!/bin/bash
rails server -b 127.0.0.1
Put it in the same folder as your project, name it anything you want (e.g. devserv
), then
chmod +x devserv
And all you have to do is ./devserv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With