Topic: Debian 3.1 + Apache 2.0 + mod_proxy + Mongrel

At work I've been running lots of little rails apps that apache has been doing a good job of killing. I like to stay "stable" in a production environment so I was not able to move to Apache 2.2 + mod_proxy_balancer for a mongrel_cluster, but I still desired to have mongrel serve my rails content.

I've got a pretty good working solution right now and I thought I would share the steps it took to get it up and running.

Requirements:
* Apache 2.0 + mod_proxy + mod_rewrite
* Mongrel

I'm not going to go into how to set them up, you'll have to google that yourself.

First, I run most of my applications under a subfolder, not a subdomain, ie http://myserver.com/helpdesk so I needed to modify the relative url:

# Placed at the top of config/routes.rb
ActionController::AbstractRequest.relative_url_root = "/helpdesk"

Second, set up apache to pass everything through the proxy. I did this in /etc/apache2/httpd.conf. There may be a better way/location for this but I'm not an apache 2 cowboy.
<Proxy *>
  Order allow,deny
  Allow from all
</Proxy>

Third, configure the proxy for the specific rails app. I do this in the /etc/apache2/sites-available/mysite file (with mysite replaced with the actual filename)

NameVirtualHost *:80
<VirtualHost *:80>
  # Enable Rewrite Engine
  RewriteEngine On

  # All the other stuff goes here but has been truncated

  # Helpdesk Proxy
  # This rewrite rule handles the missing stylesheet/images/javascripts that occur because of our relative_url_root
  RewriteRule ^/helpdesk/(images|javascripts|stylesheets)(.*) /home/helpdesk/public/$1$2
 
  # The first proxy pass rules tell us to ignore the stylesheets/images/javascripts requested
  ProxyPass /helpdesk/images !
  ProxyPass /helpdesk/stylesheets !
  ProxyPass /helpdesk/javascripts !

  # This proxy pass tells us to go to the mongrel server
  ProxyPass /helpdesk/ http://127.0.0.1:3000/helpdesk/
  ProxyPassReverse /helpdesk/ http://127.0.0.1:3000/helpdesk/
</VirtualHost>


That should be all we need to do configuration-wise, so now we fire up the mongrel server and restart apache
www:/home/helpdesk# mongrel_server start -e production -p 3000 -d -a 127.0.0.1
www:/# /etc/init.d/apache2 force-reload

That should get you a working system with mongrel doing your Rails & Apache doing everything else. You'll notice that this example does not deal with a mongrel_cluster, although you should be able to easily adapt it.

Most code examples are usually pulled out of the air and not tested. Use at your own risk!

Re: Debian 3.1 + Apache 2.0 + mod_proxy + Mongrel

for those who don't want to google how to set up your server, you could follow jk's efforts on deploy Apache2 Mongrel and the load balancer Pen on Debian 3.1. It's a bit different than the way he did it but it works out well.

http://www.jkraemer.net/articles/2006/0 … bian-sarge

Re: Debian 3.1 + Apache 2.0 + mod_proxy + Mongrel

Thanks Jonathan! Nice tutorial over there. Maybe I'll do it that way, when we move our production server. Currently I've set it up with gems.
But it has to prove, that the packages in the respository are well maintained!

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/