Running webbrick on a different port

If you are developing more than one rails web application at a time, it may be convenient to have more than one webbrick running. In order to prevent them from colliding with each other, they have to be run (bound) to different TCP ports.

Typically, you could do this by hand by running: script/server –port=3030

This, however, requires you to remember something that you probably won’t change that often. I searched for an environment variable that would affect this option on Webrick, but I couldn’t find one.

Here is a super tiny recipe that I use for changing the port in the server script. Just change your ‘server’ script to the following.

!/usr/bin/env ruby

if ! ARGV.find { |e| e.include? "--port=" } ARGV < < "--port=3001" end

require File.dirname(FILE) + '/../config/boot' require 'commands/server'

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published.