Bind rails server to 127.0.0.1 by default Bind rails server to 127.0.0.1 by default ruby-on-rails ruby-on-rails

Bind rails server to 127.0.0.1 by default


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  endend

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/bashrails 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


I use Foreman as a process manager in development.

After adding gem 'foreman' to your Gemfile and running bundle install, create a file Procfile in the root of your application directory.

While you can add lines to manage other processes, mine just reads:

web: rails server -p $PORT -b 127.0.0.1

Then, to start the Rails server via the Procfile, run foreman start. If you have other processes here (Redis, workers) they'll boot at the same time.