Tuesday, April 24, 2007

Configuring Apache 2 with mod_proxy and mongrel_rails on SuSe 9x

In the process of forcing helping a friend with his conversion from Coldfusion to Ruby on Rails, we had to get him set up with a way to run multiple rails apps from his hosting machine. Here is what I discovered when I investigated using Apache 2 and mod_proxy to host rails apps through mongrel_rails:

NOTE: the examples use su -, but I would recommend using sudo instead.

Apache 2 / mod_proxy



mod_proxy was already installed (with yast) and just needed some configuration:


  1. su -
  2. to file /etc/sysconfig/apache2, add:
    proxy proxy_ftp proxy_http proxy_connect
    to the APACHE_MODULES= line

  3. create /etc/apache2/vhost.d/example.com.conf
    because apache isn't hosting any files, this is rather shorter than his apache/coldfusion vhost files


    <VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName www.example.com

    # if not specified, the global error log is used
    ErrorLog /var/log/apache2/example.com-error_log
    CustomLog /var/log/apache2/example.com-access_log combined

    # Avoid open your server to proxying
    ProxyRequests Off

    # Let apache correctly rewrite redirect
    ProxyPass / http://hishostname.com:8000/
    ProxyPassReverse / http://hishostname.com:8000/

    # Let apache pass the original host not the ProxyPass one
    ProxyPreserveHost On

    # don't lose time with IP address lookups
    HostnameLookups Off

    # needed for named virtual hosts
    UseCanonicalName Off

    # configures the footer on server-generated documents
    ServerSignature On
    </VirtualHost>



mongrel_rails



  1. su -
  2. gem install mongrel -y
  3. export your source from version control to a likely directory (preferably as a non root user)
  4. cd to your base rails directory
  5. type something along the following lines:

    mongrel_rails start -e production -d -p 8000 -l log/mongrel.log -n 20



anyway, thats it man. its freakin magnificent.
except the SuSe part. Get a useable server, yast sucks.

--Christopher

No comments: