Posts Tagged ‘rails server setup’

Apache + Mongrel+ Mod_deflate for Ruby On Rails ( compression of scripts and CSS to increase perfomance in page loading on Rails)

August 3rd, 2009

1.Download latest version of Apache HTTP Server.

2.Untar the file and change directory to the httpd folder created on uncompression.

3.Do the Apche compilation as Root user as follows:

#./configure –prefix=/opt/installs/apache2 –enable-deflate –enable-proxy –enable-proxy-html –enable-proxy-balancer –enable-rewrite –enable-cache–enable-mem-cache –enable-ssl –enable-headers

#make

#make install

*note it should be –enable so edit it if ists shown as ‘-’ on copying ..I had faced that many times on copy-paste ;)

Add the following entries at end of httpd.conf

#note: This to connect Apache with Mongrel on 4000 and 4001 ports, if you wanna add a differnt server use that servers local or public IP instead of 127.0.0.1

#added on rails clustering by anoop

<Proxy balancer://mycluster>

# cluster member 1

BalancerMember http://127.0.0.1:6000

BalancerMember http://127.0.0.1:6001

</proxy>

#these virtual host contains the main configurations including mod deflate rules
<VirtualHost *:80>

ServerAdmin admin@greentripp.in

ServerName localhost.localdomain

ServerAlias localhost

ProxyPass / balancer://mycluster/

ProxyPassReverse / balancer://mycluster/

ErrorLog /var/log/apache_error_log

CustomLog /var/log/apache_access_log combined

#Deflate rules used in LB1 by anoop

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript

DeflateCompressionLevel 9

BrowserMatch ^Mozilla/4 gzip-only-text/html

BrowserMatch ^Mozilla/4\.0[678] no-gzip

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

DeflateFilterNote Input instream

DeflateFilterNote Output outstream

DeflateFilterNote Ratio ratio

</VirtualHost>

Confs. over

Now start mongrel_cluster from the root folder of your rails application

# mongrel_rails start -d -e production -p 6000

# mongrel_rails start -d -e production -p 6001 -P logs/mongrel2.pid

*you may add

Start Apache HTTP server:

#/opt/installs/apache2/bin/apachectl -k start

Retweet this post