You can set the mod_deflate
directive within the httpd.conf
file to enable the IBM HTTP Server to compress output files and log the compression ratios. mod_deflate
is an Apache module in the httpd.conf
file that compresses content sent from the web server to the client browser.
This appendix contains the following topics:
Regular text and most non-image content are well suited for compression. Text files can typically be compressed by 70% or more. Compression can save significant bandwidth and enable faster browser response times. The effect is negligible in most high speed LAN environments, but is quite noticeable for users on slow WAN connections.
Compression is not recommended for files that are already compressed. A partial list includes these types of files:
zip
exe
image files
Compressing these file types using mod_deflate can actually increase their size or corrupt the files.
There are 9 levels of compression available when using mod_deflate. The difference between the default level (6) and the maximum compression level (9) is minimal, and the cost in extra CPU time necessary to process the higher compression level is significant and ultimately not beneficial. For this reason, you should use the default compression level.
For specific instructions to configure the mod_deflate directive, access the Apache documentation on this web page, http://httpd.apache.org/docs/2.0/
, and click on the link for http://httpd.apache.org/docs/2.0/mod/directives.html
. Refer to this web page for instructions to configure each of the parameters discussed below. Also refer to the sample mod_deflate
module at the end of this appendix.
To enable compression, open the httpd.conf
file, and verify that the LoadModule deflate_module is uncommented (see the example below). You can configure mod_deflate to compress documents in one of two ways (both of which are specified in the httpd.conf
file):
Explicit exclusion of files by extension
This method lists the file types that should NOT be compressed by the http server.
Explicit inclusion of files by MIME type.
This method lists file types that should always be compressed by the http server.
The following three directives can be added to the httpd.conf
file to enable the writing of compression statistics to a log file. These directives will record the bytes before compression (Input), the bytes after compression (Output), and calculate the compression ratio:
DeflateFilterNote Input instream DeflateFilterNote Output outstream DeflateFilterNote Ratio ratio
The following line defines a new logging format to be used for the compression log. The format is named "deflate." The second line below specifies the path and file name of the log file (deflate.log) where the output is written.
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate CustomLog /u01/IBM/HTTPServer/logs/deflate.log deflate
The following load module line enables compression for EnterpriseOne. Verify that the line is uncommented in the httpd.conf
file.
LoadModule deflate_module modules/mod_deflate.so
In the httpd.conf
file, add the following lines under the existing <IfModule mod_deflate.c> section. Note that the compression method used in this example is explicit exclusion.
For specific instructions to configure the mod_deflate directive, access the Apache documentation on this web page, http://httpd.apache.org/docs/2.0/
, and click on the link for http://httpd.apache.org/docs/2.0/mod/directives.html
.
<IfModule mod_deflate.c> DeflateFilterNote Input instream DeflateFilterNote Output outstream DeflateFilterNote Ratio ratio LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate CustomLog /u01/IBM/HTTPServer/logs/deflate.logdeflate <Location / > # Insert filter SetOutputFilter DEFLATE # Don't compress images or binaries SetEnvIfNoCase Request_URI \ \.(?:gif|[jm]pe?g|png|t?gz|bz2*|zip|exe|iso|avi)$ no-gzip dont-vary </Location> </IfModule>