Loading Mod Deflate

First make sure that you are loading mod_deflate.so, this line should be at the top of your httpd.conf file and is usually loaded by default.

LoadModule deflate_module libexec/apache22/mod_deflate.so

Mod Deflate Settings

Second create a new config file to keep the deflate options in.

# ee /usr/local/etc/apache22/Include/mod_deflate.conf

This file will be included in the main httpd.conf file. Inside the file add the following:

AddOutputFilterByType DEFLATE text/html text/plain
#Highest 9 - Lowest 1
DeflateCompressionLevel 9

#Skip browsers with known problems
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

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

The compression level can be adjusted. 9 gives the highest compression, the smallest file sizes, and also uses the most CPU cycles.

Once you have this config file added restart apache.

# apachectl graceful

Testing Mod Deflate

To test your compression you can compare the file size by looking at the apache logs or a tool use as port80 tools.

Compressing additional types

You can compression additional mime types coming out of your server by adding them to the AddOutputFilterByType list in the mod_deflate.conf file. Some you might want to add are text/css, application/x-javascript, text/xml, and any others that are would benefit from being compressed.

Source: http://www.freebsdmadeeasy.com

Post By Editor (2,827 Posts)

Website: →