Thursday, October 26, 2006

Rails Setup With Mongrel and Apache mod_proxy

I set up Apache to proxy requests to the 3 Mongrel servers providing blogging, wiki, and todo list functionality.

This setup is for local access only.

  • Create mongrel system group and user

  • Place Rails applications in /var/www/mongrel

  • chown -R mongrel:mongrel /var/www/mongrel

  • Create mongrel initscript: /etc/init.d/mongrel and symlink to /etc/rc2.d/S99mongrel

case $1 in
for appdir in `ls /var/www/mongrel`; do cd /var/www/mongrel/$appdir ; echo " * Starting $appdir on port $port."
mongrel_rails start -d -e production -p $port --user mongrel --group mongrel -a ; port=`echo "$port + 1" | bc`
for appdir in `ls /var/www/mongrel`; do cd /var/www/mongrel/$appdir ; echo -n " * Stopping $appdir..."
mongrel_rails stop ; done
for appdir in `ls /var/www/mongrel`; do cd /var/www/mongrel/$appdir ; echo -n " * Restarting $appdir..."
mongrel_rails restart ; done

  • Start mongrel service and test

  • Add entries for blog.localhost, wiki.localhost, etc. to /etc/hosts

  • Enable mod_proxy (sudo a2enmod proxy)

  • Allow local proxy requests by modifying the /etc/apache2/mods-enabled/proxy.conf (Allow

  • Add Listen, etc. to /etc/apache2/ports.conf

  • Create VirtualHosts entries for the servers in a new sites-enabled file (I used proxy)

NameVirtualHost wiki.localhost:80
<VirtualHost wiki.localhost:80>
<Directory "/">
Order allow,deny
Allow from all
ProxyPass / http://localhost:12000/

  • Restart Apache

No comments: