Server Setup

Posted by topher
on Thursday, July 05

I have a VPS from Rimuhosting and I’m using nginx and a cluster of mongrel for my rails applications. I followed this tutorial which guides you on setting up everything – ruby, rails, nginx, mongrel, postgresql, subversion and capistrano. I’m sharing my vps with some friends and ruby, rails, and mysql were already installed. I’m using Dreamhost for subversion. Setting up nginx and mongrel is easy. I just followed the tutorial and didn’t encounter any problem.

Mongrel is a fast HTTP library and server for Ruby that is intended for hosting Ruby web applications of any kind using plain HTTP rather than FastCGI or SCGI. It is framework agnostic and already supports Ruby On Rails, Og+Nitro, Camping, and IOWA frameworks.

I use nginx for this reason (taken from the faq page in mongrel website):

Ruby on Rails is not thread safe so there is a synchronized block around the calls to Dispatcher.dispatch. This means that everything is threaded right before and right after Rails runs. While Rails is running there is only one controller in operation at a time. This is why people typically have to run a small set of Mongrel processes (a “Pack of Mongrels”) to get good concurrency.

For a rails application, I run 2 mongrel servers. I use the gem mongrel_cluster to manage these mongrels (this is in the tutorial). For example, mongrels are running in port 7500 and 7501. When a request is made, nginx passes that request to one of the mongrels. For bigger applications, use more mongrels.

Since I’m sharing the VPS with my friends, I can’t change the web server easily. Besides, they are running php and though it’s possible to run php in nginx I haven’t researched that yet. We are using Apache 2.0 which is not easy to set up with mongrel. Apache 2.2 is recommended. I have to run nginx on a different port, say 8088. Then on the apache conf file, I put this

1
2
3
4
5
6
7
8
9
10
<VirtualHost *:80>
        ServerName topher.88-mph.net
        ServerAdmin crigor@gmail.com
        ProxyRequests Off
        ProxyPreserveHost on
        <Location />
          ProxyPass http://topher.88-mph.net:8088/
          ProxyPassReverse http://topher.88-mph.net:8088/
        </Location>
</VirtualHost>

When you go to topher.88-mph.net, apache gets the request then passes it to ngingx which in turns passes it to one of the mongrels. Apache is not really needed on this set up.