Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind rails server to 127.0.0.1 by default

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

?

like image 203
Allyl Isocyanate Avatar asked Apr 29 '15 13:04

Allyl Isocyanate


2 Answers

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?

like image 93
Jorge de los Santos Avatar answered Oct 24 '22 21:10

Jorge de los Santos


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

like image 32
sjagr Avatar answered Oct 24 '22 21:10

sjagr