Dec 10, 2011

GZIP Compression in Apache


GZIP Compression in Apache Webserver

Introduction:

            The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.
            The mod_deflate module does not have a lower bound for file size, so it attempts to compress files that are too small to benefit from compression. This results in files smaller than approximately 120 bytes becoming larger when processed by mod_deflate.

Release:
RedHat Enterprise Linux
Apache Webserver 2.x

Problem:
Need to enable the gzip compression in the apache webaserver using the mod_deflate module.

Solution:

1)       Make sure that mod_deflate module is loaded in the configuration file
2)       Mention what type of files gets compressed in the http configuration file

            BrowserMatch ^Mozilla/4 gzip-only-text/html
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
            BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

3)       Add the exception using the blow syntax

            SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
            SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

Note: The above two lines mention that don't compress the image files (gif,jpe and png) and the pdf files. Like the above syntax we can exclude any other format.

4)       If u want to enable the seperate log for the gzip compression use the blow entries in the http configuration file.

            <IfModule mod_deflate.c>
            DeflateFilterNote Input inputstream
            DeflateFilterNote Output outputstream
            DeflateFilterNote Ratio ratiostream
            LogFormat '"%r" %{outputstream}n/%{inputstream}n (%{ratiostream}n%%)' deflate
            </IfModule>        

Note: In the log, how much the pages are compressed information available.

5)       Restart the http service to take the changes effect.

                        # service httpd restart






No comments: