Topic: Why :3000?

I had Rails installed on my Redhat/Apache server and it only works when I SSH:

cd public_html
cd depot
rails script/server

...And access it at

First off, how can I get the server to run constantly?  Secondly, is it possible to make it so that I don't have to have :3000 at the end for it to work?


Re: Why :3000?

When your run script/server, it is owned by the parent process, in this case the shell. You don't get your shell back until you kill the server. Now, depending on how you have Rails installed, it may be running one of several servers:

- WEBrick (a Ruby server that is the fall-back option for Rails)
- lighttpd (a very capable general-purpose http server)
- Mongrel (a server that is suited particularly well for Rails applications)

The server command looks in your path to see which of these it can use. The default port for Rails apps is 3000 and if I had to venture a guess as to why, I'd guess it's because it's a high port number that you can selectively protect with a firewall (but I don't know the real answer). If you don't like 3000, just use:

script/server -p 8080

or some other port. If you want to actually start the server as a daemon and get your shell back, then use:

script/server -p 8080 -d

Personally, I use Mongrel for everything and prefer to start it as:

mongrel_rails mongrel::start -d

You can then use:

mongrel_rails mongrel::restart


mongrel_rails mongrel::stop

to manage the server process.

Here's more complete info on script/server:

mycomputer:~/rails/myproj zzzzzz$ script/server --help
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
Usage: server [options]
    -p, --port=port                  Runs Rails on the specified port.
                                     Default: 3000
    -b, --binding=ip                 Binds Rails to the specified ip.
    -d, --daemon                     Make server run as a Daemon.
    -e, --environment=name           Specifies the environment to run this server under (test/development/production).
                                     Default: development

    -h, --help                       Show this help message.

You almost certainly don't want your Rails app to be located in a world-readable directory like public_html. It'll run just fine anyplace on your machine. I have mine set up:


So now you know about the magic -d option for the server. The final piece of the puzzle is that you need Apache to proxy to port 3000 or whatever you decide on. Here's a snippet of httpd.conf that will set up a virtual host proxied to a port (I used port 3000 for this example):

<VirtualHost *:80>
   DocumentRoot /var/www/rails/yourdomain/public
   ProxyRequests off
   ProxyPass / http://localhost:3000/
   ProxyPassReverse / http://localhost:3000
   ProxyPreserveHost on

Last edited by cwd (2007-01-07 02:54:10)

Re: Why :3000?

Thanks a lot for the detailed response.  I'm going to move my 'engine' folder (the rails when) to a private folder.  I made the changes and it works.