mod_deflate – saves web server traffic by compression


  • 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.
  • mod_deflate allows Apache2 to compress files and deliver them to clients
  • With mod_deflate, you can compress HTML, text or XML files to approx. 20 – 30% of their original sizes, thus saving you server traffic.
  • Compressing files causes a slightly higher load on the server

How to use it?

1. Enable mod_deflate module

When we install apache2, mod_deflate should also already be installed on system
LoadModule deflate_module modules/mod_deflate.so

2. Configure mod_deflate

We have the option to enable it for the entire apache or just for the specified virtualhots.
Also we can specify which type of files to be deflated.

If you want only a few file types to be deflated
AddOutputFilterByType DEFLATE text/html text/plain text/xml

If you want to compress all file types and exclude just a few like already compressed zip, gzip etc
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary

Whatever you choose from the step2, add the following below that

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

3. Adding log file for viewing results

Now add the following to add the log file to view how much % a particular request was deflated.

DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat ‘”%r” %{output_info}n/%{input_info}n (%{ratio_info}n%%)’ deflate
CustomLog /app/ihs/logs/mod_deflate.log deflate

4. Results

“GET /images/homepage_bg.jpg HTTP/1.1” 49182/114603 (42%)

This means
homepage_bg.jpg was the images which was deflated
Its actual size is 114603 and size after delated is 49182 and % od deflation is 42.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s