Ruby Rails Mongrel Apache Easy
October 31st, 2006
Having attempted to set ruby on rails up many times, this is by far my favourite soloution and it also happens to be the simplest. Why did i go the mongrel route? Well because FastCgi with Apache make me want to cry. Its buggy (especially on fedora and CentOS) and its a pain in the ass to setup. Where as mongrel on the other hand is a piece of cake.
In theory you could run mongrel, bind it to port 80 and do away with apache all together. There are a few reasons why i don't wanna do this:
1. I like apache, although its a bit of a resource hog its a solid and secure webserver, has tons of great features and a large community behind it.
2. The other stuff I'll be running on the server is made up of static pages and other CGI scripts for which I still believe apache is the best option.
In order to serve a rails application on the default port 80 we will use apaches mod_proxy to forward requests to the mongrel server sitting on a custom ports. To improve the performance its best to run more than once instance of the mongrel server and make use of apaches mod_proxy_balancer.
In order for this to work you'll require a server running apache 2.2 and yum.
Installing ruby
-
yum install ruby ruby-devel
-
wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
-
tar -xzf rubygems-0.9.0.tgz
-
cd rubygems-0.9.0
-
ruby setup.rb
Installing mongrel
-
gem install mongrel
Building a test rails application
-
mkdir /var/www/rails
-
cd /var/www/rails
-
rails mytest
Starting mongrel
-
adduser mongrel
-
cd mytest
-
chown -R :mongrel *
-
su mongrel
-
mongrel_rails start -d -p 3001 -P log/mongrel1.pid
-
mongrel_rails start -d -p 3002 -P log/mongrel2.pid
-
mongrel_rails start -d -p 3003 -P log/mongrel3.pid
Make sure you start mongrel in the root directory of your rails project. If successful we now have three mongrel instances. To verify type ps -aux | grep mongrel
Configuring Apache
You'll need to add the following code to your httpd.conf file
-
#define mongrel cluster
-
-
<proxy>BalancerMember http://127.0.0.1:3001
-
BalancerMember http://127.0.0.1:3002
-
BalancerMember http://127.0.0.1:3003
-
</proxy>
-
#forward requests to mongrel cluster
-
-
<virtualhost>
-
-
ServerName yourdomain.com
-
ServerAlias www.yourdomain.com
-
ProxyPass / balancer://mongrelcluster/
-
ProxyPassReverse / balancer://mongrelcluster/
-
ProxyPreserveHost on
-
</virtualhost>
Finally navigate to yourdomain.com and you should see the 'Welcome Aboard' default rails page.
del.icio.us Digg Furl Reddit Ma.gnolia RawSugar Shadows Spurl StumbleUpon Tailrank TechnoratiTags: Server Side | Ruby on Rails

Hi there,
That definitely looks easy. Where do you insert the httpd.conf text and how do you set this up for multiple domains?
Thanks,
Thomas
Has anyone got this working? Where do you put the Apache stuff? It looks unlike any conf I’ve ever seen?
Okay it seems that wordpress has stripped the tags from the Apache stuff. I’ll see if i can manage to restore them.
Fixed now
Looks simple enough; I’ll actually have to attempt ROR again.
[…] http://www.webmasterwords.com/ruby-rails-mongrel-apache-easy […]
I =do= get to the ‘Welcome Aboard”, but I can’t get any further. I always get a 500 Internal Server Error.
How do I get it to see my controllers?
Thanks,
T
I have the same problem, if somebody knows solution pleas tell us.
I don’t know about a production environment, but Instant Rails offers a pretty quick way to get a fully functional Apache, PHP, MySQL and RoR environment up and running. You can even install it onto a USB flash drive and take it out and about with you.
By the way, did you get your free RoR development ebook from SitePoint?