Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I configure Apache2 to support HTTP compression?

share|improve this question
up vote 7 down vote accepted

This requires the deflate module, so enable that. Under Ubuntu (which is what I'm using), the command for that is a2enmod deflate.

Then, use SetOutputFilter on your Proxy or Directory directive:

<ProxyMatch "^http://localhost:8080/($|app/)">
    Order allow,deny
    Allow from all
    SetOutputFilter Deflate


<Directory /var/www>
    Order allow,deny
    Allow from all
    SetOutputFilter Deflate
share|improve this answer
For other distros, you load the module by using "LoadModule deflate_module /path/to/module/" -- Just a couple of cents to a good answer. – user1797 May 6 '09 at 11:54

As the Wikipedia entry you link to notes, you can use mod_deflate or mod_gzip. See here an example with mod_gzip, which is what I use.

share|improve this answer
<VirtualHost *:80>
   DeflateBufferSize 16384
   DeflateCompressionLevel 5
   DeflateMemLevel 9
   DeflateWindowSize 15

   <Location / >
      AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
share|improve this answer

Depending on your deploy place this in your conf.d or extras folder as mod_deflate.conf:

# Enable mod_deflate (gzip)
    SetOutputFilter DEFLATE
    # Do not attempt to compress the following extensions
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png|swf|flv|zip|gz|tar|mp3|mp4|m4v)$ no-gzip dont-vary

Restart apache and mod_deflate will occur on all extensions not matching the regex above, this reduces the overall CPU overhead as it prevents mod_deflate from attempting to compress a format you will see little or no compression for (because it is already compressed).

To see what exactly is being compressed, and the compression ratio, place this in your

# Deflate accurate logging
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    CustomLog logs/yourdomain_deflate.log
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.