2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_deflate.xml.meta">
25 <name>mod_deflate</name>
26 <description>Compress content before it is delivered to the
28 <status>Extension</status>
29 <sourcefile>mod_deflate.c</sourcefile>
30 <identifier>deflate_module</identifier>
33 <p>The <module>mod_deflate</module> module provides
34 the <code>DEFLATE</code> output filter that allows output from
35 your server to be compressed before being sent to the client over
38 <seealso><a href="../filter.html">Filters</a></seealso>
40 <section id="recommended"><title>Sample Configurations</title>
41 <note type="warning"><title>Compression and TLS</title>
42 <p>Some web applications are vulnerable to an information disclosure
43 attack when a TLS connection carries deflate compressed data. For more
44 information, review the details of the "BREACH" family of attacks.</p>
46 <p>This is a simple configuration that compresses common text-based content types.</p>
48 <example><title>Compress only a few types</title>
49 <highlight language="config">
50 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
56 <section id="enable"><title>Enabling Compression</title>
57 <note type="warning"><title>Compression and TLS</title>
58 <p>Some web applications are vulnerable to an information disclosure
59 attack when a TLS connection carries deflate compressed data. For more
60 information, review the details of the "BREACH" family of attacks.</p>
63 <section id="output"><title>Output Compression</title>
64 <p>Compression is implemented by the <code>DEFLATE</code>
65 <a href="../filter.html">filter</a>. The following directive
66 will enable compression for documents in the container where it
69 <highlight language="config">
70 SetOutputFilter DEFLATE
71 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
74 <p>If you want to restrict the compression to particular MIME types
75 in general, you may use the <directive module="mod_filter"
76 >AddOutputFilterByType</directive> directive. Here is an example of
77 enabling compression only for the html files of the Apache
80 <highlight language="config">
81 <Directory "/your-server-root/manual">
82 AddOutputFilterByType DEFLATE text/html
86 <note><title>Note</title>
87 The <code>DEFLATE</code> filter is always inserted after RESOURCE
88 filters like PHP or SSI. It never touches internal subrequests.
90 <note><title>Note</title>
91 There is an environment variable <code>force-gzip</code>,
92 set via <directive module="mod_env">SetEnv</directive>, which
93 will ignore the accept-encoding setting of your browser and will
94 send compressed output.
98 <section id="inflate"><title>Output Decompression</title>
99 <p>The <module>mod_deflate</module> module also provides a filter for
100 inflating/uncompressing a gzip compressed response body. In order to activate
101 this feature you have to insert the <code>INFLATE</code> filter into
102 the output filter chain using <directive module="core"
103 >SetOutputFilter</directive> or <directive module="mod_mime"
104 >AddOutputFilter</directive>, for example:</p>
106 <highlight language="config">
107 <Location /dav-area>
108 ProxyPass http://example.com/
109 SetOutputFilter INFLATE
113 <p>This Example will uncompress gzip'ed output from example.com, so other
114 filters can do further processing with it.
118 <section id="input"><title>Input Decompression</title>
119 <p>The <module>mod_deflate</module> module also provides a filter for
120 decompressing a gzip compressed request body . In order to activate
121 this feature you have to insert the <code>DEFLATE</code> filter into
122 the input filter chain using <directive module="core"
123 >SetInputFilter</directive> or <directive module="mod_mime"
124 >AddInputFilter</directive>, for example:</p>
126 <highlight language="config">
127 <Location /dav-area>
128 SetInputFilter DEFLATE
132 <p>Now if a request contains a <code>Content-Encoding:
133 gzip</code> header, the body will be automatically decompressed.
134 Few browsers have the ability to gzip request bodies. However,
135 some special applications actually do support request
136 compression, for instance some <a
137 href="http://www.webdav.org">WebDAV</a> clients.</p>
139 <note type="warning"><title>Note on Content-Length</title>
140 <p>If you evaluate the request body yourself, <em>don't trust
141 the <code>Content-Length</code> header!</em>
142 The Content-Length header reflects the length of the
143 incoming data from the client and <em>not</em> the byte count of
144 the decompressed data stream.</p>
149 <section id="proxies"><title>Dealing with proxy servers</title>
151 <p>The <module>mod_deflate</module> module sends a <code>Vary:
152 Accept-Encoding</code> HTTP response header to alert proxies that
153 a cached response should be sent only to clients that send the
154 appropriate <code>Accept-Encoding</code> request header. This
155 prevents compressed content from being sent to a client that will
156 not understand it.</p>
158 <p>If you use some special exclusions dependent
159 on, for example, the <code>User-Agent</code> header, you must
160 manually configure an addition to the <code>Vary</code> header
161 to alert proxies of the additional restrictions. For example,
162 in a typical configuration where the addition of the <code>DEFLATE</code>
163 filter depends on the <code>User-Agent</code>, you should add:</p>
165 <highlight language="config">
166 Header append Vary User-Agent
169 <p>If your decision about compression depends on other information
170 than request headers (<em>e.g.</em> HTTP version), you have to set the
171 <code>Vary</code> header to the value <code>*</code>. This prevents
172 compliant proxies from caching entirely.</p>
174 <example><title>Example</title>
175 <highlight language="config">
182 <name>DeflateFilterNote</name>
183 <description>Places the compression ratio in a note for logging</description>
184 <syntax>DeflateFilterNote [<var>type</var>] <var>notename</var></syntax>
185 <contextlist><context>server config</context><context>virtual host</context>
189 <p>The <directive>DeflateFilterNote</directive> directive
190 specifies that a note about compression ratios should be attached
191 to the request. The name of the note is the value specified for
192 the directive. You can use that note for statistical purposes by
193 adding the value to your <a href="../logs.html#accesslog"
196 <example><title>Example</title>
197 <highlight language="config">
198 DeflateFilterNote ratio
200 LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate
201 CustomLog logs/deflate_log deflate
205 <p>If you want to extract more accurate values from your logs, you
206 can use the <var>type</var> argument to specify the type of data
207 left as a note for logging. <var>type</var> can be one of:</p>
210 <dt><code>Input</code></dt>
211 <dd>Store the byte count of the filter's input stream in the note.</dd>
213 <dt><code>Output</code></dt>
214 <dd>Store the byte count of the filter's output stream in the note.</dd>
216 <dt><code>Ratio</code></dt>
217 <dd>Store the compression ratio (<code>output/input * 100</code>)
218 in the note. This is the default, if the <var>type</var> argument
222 <p>Thus you may log it this way:</p>
224 <example><title>Accurate Logging</title>
225 <highlight language="config">
226 DeflateFilterNote Input instream
227 DeflateFilterNote Output outstream
228 DeflateFilterNote Ratio ratio
230 LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
231 CustomLog logs/deflate_log deflate
235 <seealso><module>mod_log_config</module></seealso>
239 <name>DeflateBufferSize</name>
240 <description>Fragment size to be compressed at one time by zlib</description>
241 <syntax>DeflateBufferSize <var>value</var></syntax>
242 <default>DeflateBufferSize 8096</default>
243 <contextlist><context>server config</context><context>virtual host</context>
247 <p>The <directive>DeflateBufferSize</directive> directive specifies
248 the size in bytes of the fragments that zlib should compress at one
254 <name>DeflateWindowSize</name>
255 <description>Zlib compression window size</description>
256 <syntax>DeflateWindowSize <var>value</var></syntax>
257 <default>DeflateWindowSize 15</default>
258 <contextlist><context>server config</context><context>virtual host</context>
262 <p>The <directive>DeflateWindowSize</directive> directive specifies the
263 zlib compression window size (a value between 1 and 15). Generally, the
264 higher the window size, the higher can the compression ratio be expected.</p>
270 <name>DeflateMemLevel</name>
271 <description>How much memory should be used by zlib for compression</description>
272 <syntax>DeflateMemLevel <var>value</var></syntax>
273 <default>DeflateMemLevel 9</default>
274 <contextlist><context>server config</context><context>virtual host</context>
278 <p>The <directive>DeflateMemLevel</directive> directive specifies
279 how much memory should be used by zlib for compression
280 (a value between 1 and 9).</p>
285 <name>DeflateCompressionLevel</name>
286 <description>How much compression do we apply to the output</description>
287 <syntax>DeflateCompressionLevel <var>value</var></syntax>
288 <default>Zlib's default</default>
289 <contextlist><context>server config</context><context>virtual host</context>
293 <p>The <directive>DeflateCompressionLevel</directive> directive specifies
294 what level of compression should be used, the higher the value,
295 the better the compression, but the more CPU time is required to
297 <p>The value must between 1 (less compression) and 9 (more compression).</p>
302 <name>DeflateAlterETag</name>
303 <description>How the outgoing ETag header should be modified during compression</description>
304 <syntax>DeflateAlterETag AddSuffix|NoChange|Remove</syntax>
305 <default>DeflateAlterETag AddSuffix</default>
306 <contextlist><context>server config</context><context>virtual host</context>
310 <p>The <directive>DeflateAlterETag</directive> directive specifies
311 how the ETag hader should be altered when a response is compressed.</p>
314 <dd><p>Append the compression method onto the end of the ETag, causing
315 compressed and uncompressed representations to have unique ETags.
316 This has been the default since 2.4.0, but prevents serving
317 "HTTP Not Modified" (304) responses to conditional requests for
318 compressed content.</p></dd>
320 <dd><p>Don't change the ETag on a compressed response. This was the default
321 prior to 2.4.0, but does not satisfy the HTTP/1.1 property that all
322 representations of the same resource have unique ETags. </p></dd>
324 <dd><p>Remove the ETag header from compressed responses. This prevents
325 some conditional requests from being possible, but avoids the
326 shortcomings of the preceding options. </p></dd>
332 <name>DeflateInflateLimitRequestBody</name>
333 <description>Maximum size of inflated request bodies</description>
334 <syntax>DeflateInflateLimitRequestBody<var>value</var></syntax>
335 <default>None, but LimitRequestBody applies after deflation</default>
336 <contextlist><context>server config</context><context>virtual host</context>
337 <context>directory</context><context>.htaccess</context></contextlist>
338 <compatibility>2.4.10 and later</compatibility>
341 <p>The <directive>DeflateInflateLimitRequestBody</directive> directive
342 specifies the maximum size of an inflated request body. If it is unset,
343 <directive module="core">LimitRequestBody</directive> is applied to the
349 <name>DeflateInflateRatioLimit</name>
350 <description>Maximum inflation ratio for request bodies</description>
351 <syntax>DeflateInflateRatioLimit <var>value</var></syntax>
352 <default>200</default>
353 <contextlist><context>server config</context><context>virtual host</context>
354 <context>directory</context><context>.htaccess</context></contextlist>
355 <compatibility>2.4.10 and later</compatibility>
358 <p>The <directive>DeflateInflateRatioLimit</directive> directive
359 specifies the maximum ratio of deflated to inflated size of an
360 inflated request body. This ratio is checked as the body is
361 streamed in, and if crossed more than
362 <directive>DeflateInflateRatioBurst</directive> times, the request
363 will be terminated.</p>
368 <name>DeflateInflateRatioBurst</name>
369 <description>Maximum number of times the inflation ratio for request bodies
370 can be crossed</description>
371 <syntax>DeflateInflateRatioBurst <var>value</var></syntax>
373 <contextlist><context>server config</context><context>virtual host</context>
374 <context>directory</context><context>.htaccess</context></contextlist>
375 <compatibility>2.4.10 and later</compatibility>
378 <p>The <directive>DeflateInflateRatioBurst</directive> directive
379 specifies the maximum number of times the
380 <directive>DeflateInflateRatioLimit</directive> cab be crossed before
381 terminating the request.</p>