Configure mod deflate for Apache 2.2.x

by admin on June 8, 2009
in Apache

Mod Deflate comes built into Apache, but is not enabled by default. This tutorial will explain the simplest way of enabling it and setting which mime times to compress. Mod Deflate will increase your server load, but decreases the amount of time that clients are connected and can usually reduce the page size by 60 to 80 percent.

  1. 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
  2. Mod Deflate Settings

    Then add this too httpd.conf

    AddOutputFilterByType DEFLATE text/html text/plain
    #Highest 9 - Lowest 1
    DeflateCompressionLevel 9
    #Optional
    #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
    #Optional
    #Logging
    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.

  3. Once you have this config file added restart apache.
    service httpd restart

Post a Comment