Hosting Rails applications with mongrel , Apache 2 & mod_proxy on Debian Stable

About ten months ago I switched from Apache 2 to `lighttpd` for hosting this site. This was back in the day when the only real way to run your rails app was through FastCGI.

Times change and now all the cool kids are using Mongrel or clusters thereof. I tried to get Mongrel running with Lighty, but I gave up for two reasons:

1. The maintainer of Mongrel recommends not to use lighttpd because of issues 2. Whilst ignoring him and pressing on regardless my Lighty install fubar’d and I couldn’t recover it. It just wouldn’t serve any content anymore – dynamic or static

So I decided to swtich back to Apache 2. There are various guides around for hosting mongrel behind a load balancer behind Apache 2.2, but the load balancer isn’t available for Apache 2.0 and there’s little documentation for alternatives. Balancing would be nice, but it’s not my main objective here so I did some more digging and concluded that `mod_proxy` would meet my needs.

First of all I got Mongrel running and made sure it worked:

$ cd typo
$ mongrel_rails start -d -e production

Enabling `mod_proxy` is simple enough:

$ a2enmod proxy

Now I’m using name based virtual hosting on my server, so for the domain (this one) I wanted to reverse proxy to mongrel I added the following to the relevant file in `/etc/apache2/sites-available/`:

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

Fired up my browser, pointed it to http://schwuk.com and… it didn’t work.

I kept getting 403 errors, but I just couldn’t figure out why. After a bit more googling I found the solution. Change your `/etc/apache2/mods-available/proxy.conf` from:

Order deny,allow Deny from all #Allow from .your_domain.com

To:

Order deny,allow Allow from all

Cap it all off with a:

$ /etc/init.d/apache2 force-reload

...and you should be good to go!