Apache Module mod_deflate
module provides the mod_deflateDEFLATE
output filter that allows output from your server to be compressed before being sent to the client over the network.
This is a simple configuration that compresses common text-based content types.
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
filter. The following directive will enable compression for documents in the container where it is placed:
SetOutputFilter DEFLATE SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
If you want to restrict the compression to particular MIME types in general, you may use the
directive. Here is an example of enabling compression only for the html files of the Apache documentation:AddOutputFilterByType
filter is always inserted after RESOURCE filters like PHP or SSI. It never touches internal subrequests. force-gzip
, which will ignore the accept-encoding setting of your browser and will send compressed output. The
module also provides a filter for inflating/uncompressing a gzip compressed response body. In order to activate this feature you have to insert the mod_deflateINFLATE
filter into the outputfilter chain using
This Example will uncompress gzip'ed output from example.com, so other filters can do further processing with it.
header, the body will be automatically decompressed. Few browsers have the ability to gzip request bodies. However, some special applications actually do support request compression, for instance some WebDAV clients.
If you evaluate the request body yourself, don't trust the Content-Length header! The Content-Length header reflects the length of the incoming data from the client and
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
If your decision about compression depends on other information than request headers (e.g. HTTP version), you have to set the Vary
. This prevents compliant proxies from caching entirely.
DeflateFilterNote ratio LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate CustomLog logs/deflate_log deflate
If you want to extract more accurate values from your logs, you can use the type argument to specify the type of data left as note for logging. type can be one of:
) in the note. This is the default, if the Thus you may log it this way:
DeflateFilterNote Input instream DeflateFilterNote Output outstream DeflateFilterNote Ratio ratio LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate CustomLog logs/deflate_log deflate
None, but LimitRequestBody applies after deflation
Modules | Directives | FAQ | Glossary | Sitemap
Apache HTTP Server Version 2.4
Apache Module mod_deflate
Available Languages: en | fr | ja | ko
Enabling Compression
Some web applications are vulnerable to an information disclosure attack when a TLS connection carries deflate compressed data. For more information, review the details of the "BREACH" family of attacks.
Dealing with proxy servers
The 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. This prevents compressed content from being sent to a client that will not understand it.
DeflateBufferSize Directive
The DeflateBufferSize directive specifies the size in bytes of the fragments that zlib should compress at one time.
DeflateCompressionLevel Directive
The DeflateCompressionLevel directive specifies what level of compression should be used, the higher the value, the better the compression, but the more CPU time is required to achieve this.
DeflateFilterNote Directive
The DeflateFilterNote directive specifies that a note about compression ratios should be attached to the request. The name of the note is the value specified for the directive. You can use that note for statistical purposes by adding the value to your access log.
DeflateInflateLimitRequestBody Directive
The DeflateInflateLimitRequestBody directive specifies the maximum size of an inflated request body. If it is unset, LimitRequestBody is applied to the inflated body.
DeflateInflateRatioBurst Directive
The DeflateInflateRatioBurst directive specifies the maximum number of times the DeflateInflateRatioLimit cab be crossed before terminating the request.
DeflateInflateRatioLimit Directive
The DeflateInflateRatioLimit directive specifies the maximum ratio of deflated to inflated size of an inflated request body. This ratio is checked as the body is streamed in, and if crossed more than DeflateInflateRatioBurst times the request will be terminated.
DeflateMemLevel Directive
The DeflateMemLevel directive specifies how much memory should be used by zlib for compression (a value between 1 and 9).
DeflateWindowSize Directive
The DeflateWindowSize directive specifies the zlib compression window size (a value between 1 and 15). Generally, the higher the window size, the higher can the compression ratio be expected.