mod_deflate is a module that been loaded by Apache HTTPD server to compress web pages in GZIP encoding before serving and transferring the web pages across Internet to requesting web browser. GZIP compression can potentially reduces and shrinks the size of the files by between 60% to 80%., reducing the traffic bandwidth required to serve the request.

mod_deflate has built-in directive which able to log the compression ratio or the percentage of the reduction in page size. The directive, DeflateFilterNote, specifies that a note about compression ratios of the transmitted web pages or files should be attached to the request.

In order to log the compression ratio achieved by mod_deflate, add in the following lines of code into Apache config file, typically named httpd.conf.

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate

Above code will extract accurate values from the logs, with the type argument been used to specify the type of data left as note for logging. The location for the log to be saved, named as deflate_log in the example above, is to be changed accordingly. The example of the log been captured are:

“GET /index.php HTTP/1.1” 8888/77777 (11%)

Where index.php is been requested, with 77777 bytes as its original size, 8888 bytes the compressed size, representing 11% of the original size. A simpler version of the logging code for mod_deflate is as follow:

DeflateFilterNote ratio
LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate
CustomLog logs/deflate_log deflate

Restart Apache web server after saving the httpd.conf, with the following command.

/etc/init.d/apache2 restart


/etc/init.d/httpd restart