Jul 122011

To enable web compression, we need to create a mod_deflate.conf file and also do some changes to the web server configuration – httpd.conf file.

To create the mode_deflate.config, perform the following operations:
1.    Create mod_deflate.conf file. The contents of the file are provided below:

<Location />
# Insert filter
#Comment SetOutputFilter and
#uncomment AddOutputFilterByType to disable js files compression
SetOutputFilter DEFLATE
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary


DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

#If <VirtualHost> defined then add below log config in <VirtualHost>
#Othewise uncomment here to enable deflate log
#CustomLog /opt/Apache/logs/deflate.log \
#          '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)'

2.    If VirtualHost defined then add the log directive in that section. For secure web server add the following after ssl_request_log definition.

CustomLog /opt/Apache/logs/deflate.log \
'"%r" %{outstream}n/%{instream}n (%{ratio}n%%)'

This step is optional and can be skipped.
Change the path to the log file as per your server setup.

3.    Save and close mod_deflate.conf file.
4.    Check the ownership for the file mod_deflate.conf, the web server admin should have rights for this file; change ownership if required.
5.    Restart web server.

Modify The Web Server Configuration For Web Compression

To modify the Web Server configuration file, open the file httpd.conf in the ‘<HTTPSERVER_ROOT>/conf’ directory in a simple text editor, like vi or notepad, and perform the following operations:
Uncomment headers_module loading line in the httpd.conf to enable the server to start:

LoadModule headers_module modules/mod_headers.so

Add the following in httpd.conf after the last LoadModule directive.

LoadModule deflate_module modules/mod_deflate.so
Include conf/mod_deflate.conf

 The path for mod_deflate.conf is from the web server root; modify it as per your server setup
Save and close httpd.conf file.

To check syntax use

apachectl -t

in APACHE_HOME/bin folder.

Repeat the stepsfor all the web servers in the web server cluster. Once above changes are done restart HTTP Servers to make the changes take effect.

Found Useful? +1 this post.

Did Not Find The Exact Solution..? Put A Comment With Your Question, Our Expert Tech Members Will Get Back To You!!

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>