A quick and dirty way of setting up Rails and Apache2, is using Apache’s balancer module. You’ll need to enable the proxy module, and the proxy balancer module and then setup the configuration, as follows:

Set up the load balancer, to forward requests to the localhost, port 4040

<proxy balancer://my_site.com>
        BalancerMember http://127.0.0.1:4040
        Order allow,deny
        Allow from all
</proxy>

Configure the virtual host to point to the Rails Application’s root directory, located at /var/www/my_site.com.site/

<VirtualHost *:80>
        ServerAdmin hostmaster@my_site.com

        ServerName my_site.com 
        ServerAlias www.my_site.com

        DocumentRoot /var/www/my_site.com.site/

        ErrorLog /var/log/apache2/error_my_site.com.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access_my_site.com.log combined

        ProxyPass / balancer://my_site.com/
        ProxyPassReverse / balancer://my_site.com/
        ProxyPreserveHost on
        ProxyPass /images !
        ProxyPass /stylesheets !

        Alias /images /var/www/my_site.com.site/public/images
        Alias /stylesheets /var/www/my_site.com.site/public/stylesheets

</VirtualHost>

Start the Rails app to listen on localhost, port 4040. Finally restart the Apache server. If all goes well, the Apache server will forward requests to the Rails app.

Leave a Reply