]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_deflate.xml
typo
[apache] / docs / manual / mod / mod_deflate.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <modulesynopsis>
5
6 <name>mod_deflate</name>
7 <description>Compress content before it is delivered to the
8 client</description>
9 <status>Extension</status>
10 <sourcefile>mod_deflate.c</sourcefile>
11 <identifier>deflate_module</identifier>
12
13 <summary>
14     <p>The <module>mod_deflate</module> module provides
15     the <code>DEFLATE</code> output filter that allows output from
16     your server to be compressed before being sent to the client over
17     the network.</p>
18 </summary>
19 <seealso><a href="../filter.html">The filter documentation</a></seealso>
20
21 <section id="recommended"><title>Recommended Configuration</title>
22     <p>This is a sample configuration for the impatient. But please take
23     the time and read the sections below for a detailed description!</p>
24
25     <example><title>Compress only a few types</title>
26       AddOutputFilterByType DEFLATE text/html text/plain text/xml
27     </example>
28
29     <example><title>Compress everything except images</title>
30       &lt;Location /&gt;<br />
31       <indent>
32         # Insert filter<br />
33         SetOutputFilter DEFLATE<br />
34         <br />
35         # Netscape 4.x has some problems...<br />
36         BrowserMatch ^Mozilla/4         gzip-only-text/html<br />
37         <br />
38         # Netscape 4.06-4.08 have some more problems<br />
39         BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
40         <br />
41         # MSIE masquerades as Netscape, but it is fine<br />
42         BrowserMatch \bMSIE             !no-gzip !gzip-only-text/html<br />
43         <br />
44         # Don't compress images<br />
45         SetEnvIfNoCase Request_URI \<br />
46         <indent>
47           \.(?:gif|jpe?g|png)$ no-gzip dont-vary<br />
48         </indent>
49         <br />
50         # Make sure proxies don't deliver the wrong content<br />
51         Header append Vary User-Agent env=!dont-vary<br />
52       </indent>
53       &lt;/Location&gt;
54     </example>
55
56 </section>
57
58 <section id="enable"><title>Enabling Compression</title>
59
60     <section id="output"><title>Output Compression</title>
61       <p>Compression is implemented by the <code>DEFLATE</code>
62       <a href="../filter.html">filter</a>. The following directive
63       will enable compression for documents in the container where it
64       is placed:</p>
65
66       <example>
67         SetOutputFilter DEFLATE
68       </example>
69
70       <p>Some popular browsers cannot handle compression of all content
71       so you may want to set the <code>gzip-only-text/html</code> note to
72       <code>1</code> to only allow html files to be compressed (see
73       below). If you set this to <em>anything but <code>1</code></em> it
74       will be ignored.</p>
75       
76       <p>If you want to restrict the compression to particular MIME types
77       in general, you may use the <directive module="core"
78       >AddOutputFilterByType</directive> directive. Here is an example of
79       enabling compression only for the html files of the Apache
80       documentation:</p>
81
82       <example>
83         &lt;Directory "/your-server-root/manual"&gt;<br />
84         <indent>
85           AddOutputFilterByType DEFLATE text/html<br />
86         </indent>
87         &lt;/Directory&gt;
88       </example>
89
90       <p>For browsers that have problems even with compression of all file
91       types, use the <directive module="mod_setenvif"
92       >BrowserMatch</directive> directive to set the <code>no-gzip</code>
93       note for that particular browser so that no compression will be
94       performed. You may combine <code>no-gzip</code> with <code
95       >gzip-only-text/html</code> to get the best results. In that case
96       the former overrides the latter. Take a look at the following
97       excerpt from the <a href="#recommended">configuration example</a>
98       defined in the section above:</p>
99
100       <example>
101         BrowserMatch ^Mozilla/4         gzip-only-text/html<br />
102         BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
103         BrowserMatch \bMSIE             !no-gzip !gzip-only-text/html
104       </example>
105
106       <p>At first we probe for a <code>User-Agent</code> string that
107       indicates a Netscape Navigator version of 4.x. These versions
108       cannot handle compression of types other than
109       <code>text/html</code>. The versions 4.06, 4.07 and 4.08 also
110       have problems with decompressing html files. Thus, we completely
111       turn off the deflate filter for them.</p>
112
113       <p>The third <directive module="mod_setenvif">BrowserMatch</directive>
114       directive fixes the guessed identity of the user agent, because
115       the Microsoft Internet Explorer identifies itself also as "Mozilla/4"
116       but is actually able to handle requested compression. Therefore we
117       match against the additional string "MSIE" (<code>\b</code> means
118       "word boundary") in the <code>User-Agent</code> Header and turn off
119       the restrictions defined before.</p>
120
121       <note><title>Note</title>
122         The <code>DEFLATE</code> filter is always inserted after RESOURCE
123         filters like PHP or SSI. It never touches internal subrequests.
124       </note>
125     </section>
126
127     <section id="input"><title>Input Decompression</title>
128       <p>The <module>mod_deflate</module> module also provides a filter for
129       decompressing a gzip compressed request body . In order to activate
130       this feature you have to insert the <code>DEFLATE</code> filter into
131       the input filter chain using <directive module="core"
132       >SetInputFilter</directive> or <directive module="mod_mime"
133       >AddInputFilter</directive>, for example:</p>
134
135       <example>
136         &lt;Location /dav-area&gt;<br />
137         <indent>
138           SetInputFilter DEFLATE<br />
139         </indent>
140         &lt;/Location&gt;
141       </example>
142       
143       <p>Now if a request contains a <code>Content-Encoding:
144       gzip</code> header, the body will be automatically decompressed.
145       Few browsers have the ability to gzip request bodies. However,
146       some special applications actually do support request
147       compression, for instance some <a
148       href="http://www.webdav.org">WebDAV</a> clients.</p>
149
150       <note type="warning"><title>Note on Content-Length</title>
151         <p>If you evaluate the request body yourself, <em>don't trust
152         the <code>Content-Length</code> header!</em>
153         The Content-Length header reflects the length of the
154         incoming data from the client and <em>not</em> the byte count of
155         the decompressed data stream.</p>
156       </note>
157     </section>
158 </section>
159
160 <section id="proxies"><title>Dealing with proxy servers</title>
161
162     <p>The <module>mod_deflate</module> module sends a <code>Vary:
163     Accept-Encoding</code> HTTP response header to alert proxies that
164     a cached response should be sent only to clients that send the
165     appropriate <code>Accept-Encoding</code> request header.  This
166     prevents compressed content from being sent to a client that will
167     not understand it.</p>
168
169     <p>If you use some special exclusions dependent
170     on, for example, the <code>User-Agent</code> header, you must 
171     manually configure an addition to the <code>Vary</code> header
172     to alert proxies of the additional restrictions.  For example,
173     in a typical configuration where the addition of the <code>DEFLATE</code>
174     filter depends on the <code>User-Agent</code>, you should add:</p>
175
176     <example>
177       Header append Vary User-Agent
178     </example>
179     
180     <p>If your decision about compression depends on other information
181     than request headers (<em>e.g.</em> HTTP version), you have to set the
182     <code>Vary</code> header to the value <code>*</code>. This prevents
183     compliant proxies from caching entirely.</p>
184
185     <example><title>Example</title>
186       Header set Vary *
187     </example>
188 </section>
189
190 <directivesynopsis>
191 <name>DeflateFilterNote</name>
192 <description>Places the compression ratio in a note for logging</description>
193 <syntax>DeflateFilterNote <var>notename</var></syntax>
194 <contextlist><context>server config</context><context>virtual host</context>
195 </contextlist>
196
197 <usage>
198     <p>The <directive>DeflateFilterNote</directive> directive
199     specifies that a note about compression ratios should be attached
200     to the request. The name of the note is the value specified for
201     the directive. You can use that note for statistical purposes by
202     adding the value to your <a href="../logs.html#accesslog"
203     >access log</a>.</p>
204
205     <example><title>Example</title>
206       DeflateFilterNote ratio<br />
207       <br />
208       LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate<br />
209       CustomLog logs/deflate_log deflate
210     </example>
211 </usage>
212 <seealso><module>mod_log_config</module></seealso>
213 </directivesynopsis>
214
215 <directivesynopsis>
216 <name>DeflateBufferSize</name>
217 <description>Fragment size to be compressed at one time by zlib</description>
218 <syntax>DeflateBufferSize <var>value</var></syntax>
219 <default>DeflateBufferSize 8096</default>
220 <contextlist><context>server config</context><context>virtual host</context>
221 </contextlist>
222
223 <usage>
224     <p>The <directive>DeflateBufferSize</directive> directive specifies
225     the size in bytes of the fragments that zlib should compress at one
226     time.</p>
227 </usage>
228 </directivesynopsis>
229
230 <directivesynopsis>
231 <name>DeflateWindowSize</name>
232 <description>Zlib compression window size</description>
233 <syntax>DeflateWindowSize <var>value</var></syntax>
234 <default>DeflateWindowSize 15</default>
235 <contextlist><context>server config</context><context>virtual host</context>
236 </contextlist>
237
238 <usage>
239     <p>The <directive>DeflateWindowSize</directive> directive specifies the
240     zlib compression window size (a value between 1 and 15). Generally, the
241     higher the window size, the higher can the compression ratio be expected.</p>
242 </usage>
243 </directivesynopsis>
244
245 <directivesynopsis>
246 <name>DeflateMemLevel</name>
247 <description>How much memory should be used by zlib for compression</description>
248 <syntax>DeflateMemLevel <var>value</var></syntax>
249 <default>DeflateMemLevel 9</default>
250 <contextlist><context>server config</context><context>virtual host</context>
251 </contextlist>
252
253 <usage>
254     <p>The <directive>DeflateMemLevel</directive> directive specifies
255     how much memory should be used by zlib for compression
256     (a value between 1 and 9).</p>
257 </usage>
258 </directivesynopsis>
259
260 </modulesynopsis>
261