Ruby on Rails / Apache 2 / Mongrel January 31st, 2007
Ok, so as I explained in my last post I found this nice blogging app thats written in Ruby on Rails. I learned a lot about deploying Ruby on Rails applications in a couple short hours. One of my biggest problems was with Apache 2 and fcgid. All of the docs I found said to use either fastcgi or fcgid. Fcgid is broken in Debian Etch as of right now, and fastcgi was giving me nothing but header errors. I tried mod_ruby and received a security error every time.
Mongrel was the answer to all of my problems. Mongrel is a fast, lean, and secure server for RoR (Ruby on Rails) applications. I setup Mongrel and had instant success. I used the following to start mongrel.
mongrel_rails start -d -p 8000 -e production
Make sure to do this from inside the applications directory. This will start an instance of Mongrel on port 8000. I know, you don’t want to type in http://yousite.com:8000 and it looks terrible too. This is why we are going to use Apache and its proxy module. So now we need to load the proxy module for Apache 2. Once this is done you can setup the virtual host for your domain.
<VirtualHost *>
ServerName yoursite.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://yoursite.com:8000/
ProxyPassReverse / http://yoursite.com:8000
ProxyPreserveHost on
ProxyRequests Off
ErrorLog /var/log/apache2/yoursite-com-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/yoursite-com-access.log combined
ServerSignature On
</VirtualHost>
I’m not going to get into all of the directives; However I will say that you do want to make sure you set:
ProxyRequests Off
so your server doesn’t turn into an open proxy for the world to exploit.
Now you have Mongrel running on port 8000 and Apache running on port 80. Apache is going to take all requests to http://yoursite.com/ and forward them to http://yoursite.com:8000/. This is not only helpful in speeding up the content but it’s also safer since you are running Mongrel on a non-privileged port.
If you have any questions please feel free to contact me via the comment system.
Sorry, comments are closed for this article.


