mod_deflate module applies DEFLATE filter that allows server output to be compressed before sending it to the client over the network.

Quick start

Compress only specific types

AddOutputFilterByType DEFLATE text/html text/plain text/xml

Compress everything except images

<Location />
  # Insert   filter
  SetOutputFilter DEFLATE
  # Netscape 4.x has some   problems...
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  # Netscape   4.06-4.08 have some more problems
  BrowserMatch ^Mozilla/4\.0[678]   no-gzip
  # MSIE masquerades as Netscape, but it is fine
  BrowserMatch   \bMSIE !no-gzip !gzip-only-text/html
  # Don't compress   images
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  # Make sure   proxies don't deliver the wrong content
  Header append Vary User-Agent   env=!dont-vary

Enabling Compression

Output Compression

Compression is enabled by DEFLATE filter as follows:

SetOutputFilter DEFLATE 

Some browsers do not support compression of all content types, so you may need to set gzip-only-text/html to 1 to only allow compression of html files. If you put other value than 1, it will be ignored.

If you want to restrict the compression to particular MIME types, you may use AddOutputFilterByType directive:

<Directory "/your-server-root/manual">
  AddOutputFilterByType DEFLATE text/html

Output Decompression

mod_deflate module also provides a filter for inflating/uncompressing a gzip compressed response body. In order to activate this feature you have to insert the INFLATE filter into the output filter chain using SetOutputFilter or AddOutputFilter:

<Location /dav-area>
  SetOutputFilter INFLATE

This code will uncompress gzip'ed output from, so other filters can do further processing with it.

Input Decompression

mod_deflate module also provides a filter for decompressing a gzip compressed request body. In order to activate this feature you have to insert the DEFLATE filter into the input filter chain using SetOutputFilter or AddOutputFilter:

<Location /dav-area>
    SetInputFilter   DEFLATE

Now if a request contains a Content-Encoding: gzip header, the body will be automatically decompressed. Few browsers have the ability to gzip request bodies. However, some special applications do support request compression, for instance some WebDAV clients.

Dealing with proxy servers

mod_deflate module sends a Vary: Accept-Encoding HTTP response header to alert proxies that a cached response should be sent only to clients that send the appropriate Accept-Encoding request header.

If you use some special exclusions dependent on, for example, the User-Agent header, you must manually configure an addition to the Vary header to alert proxies of the additional restrictions. For example, in a typical configuration where the addition of the DEFLATE filter depends on the User-Agent, you should add:

Header append Vary User-Agent 

If your decision about compression depends on other information than request headers (e.g. HTTP version), you have to set the Vary header to the value '*'. This prevents compliant proxies from caching entirely:

Header set Vary *

Related articles and topics


Name Context Description
DeflateCompressionLevel S V D .h defines to what extent the content must be compressed


DeflateCompressionLevel directive sets the level of compression to be applied to the content. Higher value means better compression.

Compression level value must be between 1 (minimum compression) and 9 (maximum compression).


DeflateCompressionLevel value


DeflateCompressionLevel 6