Section 4.2. Common Configurations

4.2. Common Configurations

Now that you can see how easily Mongrel can be configured, let's see what people are doing with it. Most of the configuration options will change from defaults because you want to run Mongrel in a cluster or in a production environment where you want to sit it behind a static HTTP server like Apache.

4.2.1. Mongrel Standalone

As a real HTTP server, Mongrel will work just fine as a front-facing Web server. After all, this is how it works in your development environment. Typically small Web sites will run just fine with a single Mongrel process. If you need SSL, you can run Mongrel behind a reverse-proxy like Pen. If you have request hogs like file uploads, you'll probably want to run more than one Mongrel, which means you'll need Mongrel Cluster and a reverse-proxy server.

4.2.2. A Pack of Mongrels (mongrel_cluster)

Depending on what kind of Web application you're running and how much traffic you expect, you might want to have multiple Mongrel processes running in a cluster. If you are accustomed to running multiple FCGI processes, then you will want to run a cluster of Mongrel processes (a "cluster" in this case does not mean you need separate machines, just separate processes running on a single machine). To help figure out how many Mongrels you'll need, you should read "How Many Mongrels" ( If you need at least two, then you'll want to run a cluster. You do this with the mongrel_cluster gem, written by Bradley Taylor from RailsMachine. Detailed instructions for setup and use are available on the Mongrel Web site (

4.2.3. Mongrel Behind a "Static" Web Server

A common configuration for running a Rails application these days is to have a fast, compiled Web server like Apache field incoming requests, and have it reverse-proxy to a cluster of Mongrels. We call this a "static" server setup because the front-facing server will be good at serving static content like cached pages, CSS, Javascript, and images fast. Mongrel can serve static files quickly, but Ruby will never run as fast as a compiled binary, so use that to your advantage. The static Web server is usually configured with its mod_rewrite to only pass appropriate requests to the Mongrel cluster. If you are running a fully cached site, for example, this kind of setup will never even need to call Rails. Static Server Options

Apache has been frowned upon by many Rails developers because of its flaky support for FastCGI, which was previously the least-horrible way to run a Rails application. FastCGI was pretty buggy, requiring scripts like script/spawner and script/reaper to kill and start FastCGI processes on the fly. Since Mongrel eliminates this problem, Apache has become a preferred option among those running Rails sites. We provide an example configuration with Apache in Section 5. What about LightTPD?

When FastCGI was the best option out there, LightTPD (aka Lighty) was considered a top choice for a static server, sometimes preferred over Apache. At the moment Lighty's mod_proxy module has a bug that will not properly connect to Mongrel processes if they go down and come back. This problem will be fixed in Lighty 1.5.0 with the mod_proxy_core module. Keep an eye out for Lighty announcements. Once this issue is resolved, Lighty will likely return to the shortlist.

Mongrel. Serving, Deploying, and Extending Your Ruby Applications
Mongrel. Serving, Deploying, and Extending Your Ruby Applications
ISBN: 9812836357
Year: 2006
Pages: 48 © 2008-2017.
If you may any questions please contact us: