1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>mod_deflate - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body> 17<div id="page-header"> 18<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 19<p class="apache">Apache HTTP Server Version 2.2</p> 20<img alt="" src="/images/feather.gif" /></div> 21<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 22<div id="path"> 23<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.2</a> > <a href="./">Modules</a></div> 24<div id="page-content"> 25<div id="preamble"><h1>Apache Module mod_deflate</h1> 26<div class="toplang"> 27<p><span>Available Languages: </span><a href="/en/mod/mod_deflate.html" title="English"> en </a> | 28<a href="/ja/mod/mod_deflate.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 29<a href="/ko/mod/mod_deflate.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p> 30</div> 31<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Compress content before it is delivered to the 32client</td></tr> 33<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr> 34<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>deflate_module</td></tr> 35<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_deflate.c</td></tr></table> 36<h3>Summary</h3> 37 38 <p>The <code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code> module provides 39 the <code>DEFLATE</code> output filter that allows output from 40 your server to be compressed before being sent to the client over 41 the network.</p> 42</div> 43<div id="quickview"><h3 class="directives">Directives</h3> 44<ul id="toc"> 45<li><img alt="" src="/images/down.gif" /> <a href="#deflatebuffersize">DeflateBufferSize</a></li> 46<li><img alt="" src="/images/down.gif" /> <a href="#deflatecompressionlevel">DeflateCompressionLevel</a></li> 47<li><img alt="" src="/images/down.gif" /> <a href="#deflatefilternote">DeflateFilterNote</a></li> 48<li><img alt="" src="/images/down.gif" /> <a href="#deflatememlevel">DeflateMemLevel</a></li> 49<li><img alt="" src="/images/down.gif" /> <a href="#deflatewindowsize">DeflateWindowSize</a></li> 50</ul> 51<h3>Topics</h3> 52<ul id="topics"> 53<li><img alt="" src="/images/down.gif" /> <a href="#recommended">Sample Configurations</a></li> 54<li><img alt="" src="/images/down.gif" /> <a href="#enable">Enabling Compression</a></li> 55<li><img alt="" src="/images/down.gif" /> <a href="#proxies">Dealing with proxy servers</a></li> 56</ul><h3>See also</h3> 57<ul class="seealso"> 58<li><a href="/filter.html">Filters</a></li> 59</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 60<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 61<div class="section"> 62<h2><a name="recommended" id="recommended">Sample Configurations</a></h2> 63 <p>This is a simple sample configuration for the impatient.</p> 64 65 <div class="example"><h3>Compress only a few types</h3><p><code> 66 AddOutputFilterByType DEFLATE text/html text/plain text/xml 67 </code></p></div> 68 69 <p>The following configuration, while resulting in more compressed content, 70 is also much more complicated. Do not use this unless you fully understand 71 all the configuration details.</p> 72 73 <div class="example"><h3>Compress everything except images</h3><p><code> 74 <Location /><br /> 75 <span class="indent"> 76 # Insert filter<br /> 77 SetOutputFilter DEFLATE<br /> 78 <br /> 79 # Netscape 4.x has some problems...<br /> 80 BrowserMatch ^Mozilla/4 gzip-only-text/html<br /> 81 <br /> 82 # Netscape 4.06-4.08 have some more problems<br /> 83 BrowserMatch ^Mozilla/4\.0[678] no-gzip<br /> 84 <br /> 85 # MSIE masquerades as Netscape, but it is fine<br /> 86 BrowserMatch \bMSIE !no-gzip !gzip-only-text/html<br /> 87 # Don't compress images<br /> 88 SetEnvIfNoCase Request_URI \<br /> 89 <span class="indent"> 90 \.(?:gif|jpe?g|png)$ no-gzip dont-vary<br /> 91 </span> 92 <br /> 93 # Make sure proxies don't deliver the wrong content<br /> 94 Header append Vary User-Agent env=!dont-vary<br /> 95 </span> 96 </Location> 97 </code></p></div> 98 99</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 100<div class="section"> 101<h2><a name="enable" id="enable">Enabling Compression</a></h2> 102 103 <h3><a name="output" id="output">Output Compression</a></h3> 104 <p>Compression is implemented by the <code>DEFLATE</code> 105 <a href="/filter.html">filter</a>. The following directive 106 will enable compression for documents in the container where it 107 is placed:</p> 108 109 <div class="example"><p><code> 110 SetOutputFilter DEFLATE 111 </code></p></div> 112 113 <p>Some popular browsers cannot handle compression of all content 114 so you may want to set the <code>gzip-only-text/html</code> note to 115 <code>1</code> to only allow html files to be compressed (see 116 below). If you set this to <em>anything but <code>1</code></em> it 117 will be ignored.</p> 118 119 <p>If you want to restrict the compression to particular MIME types 120 in general, you may use the <code class="directive"><a href="/mod/core.html#addoutputfilterbytype">AddOutputFilterByType</a></code> directive. Here is an example of 121 enabling compression only for the html files of the Apache 122 documentation:</p> 123 124 <div class="example"><p><code> 125 <Directory "/your-server-root/manual"><br /> 126 <span class="indent"> 127 AddOutputFilterByType DEFLATE text/html<br /> 128 </span> 129 </Directory> 130 </code></p></div> 131 132 <p>For browsers that have problems even with compression of all file 133 types, use the <code class="directive"><a href="/mod/mod_setenvif.html#browsermatch">BrowserMatch</a></code> directive to set the <code>no-gzip</code> 134 note for that particular browser so that no compression will be 135 performed. You may combine <code>no-gzip</code> with <code>gzip-only-text/html</code> to get the best results. In that case 136 the former overrides the latter. Take a look at the following 137 excerpt from the <a href="#recommended">configuration example</a> 138 defined in the section above:</p> 139 140 <div class="example"><p><code> 141 BrowserMatch ^Mozilla/4 gzip-only-text/html<br /> 142 BrowserMatch ^Mozilla/4\.0[678] no-gzip<br /> 143 BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 144 </code></p></div> 145 146 <p>At first we probe for a <code>User-Agent</code> string that 147 indicates a Netscape Navigator version of 4.x. These versions 148 cannot handle compression of types other than 149 <code>text/html</code>. The versions 4.06, 4.07 and 4.08 also 150 have problems with decompressing html files. Thus, we completely 151 turn off the deflate filter for them.</p> 152 153 <p>The third <code class="directive"><a href="/mod/mod_setenvif.html#browsermatch">BrowserMatch</a></code> 154 directive fixes the guessed identity of the user agent, because 155 the Microsoft Internet Explorer identifies itself also as "Mozilla/4" 156 but is actually able to handle requested compression. Therefore we 157 match against the additional string "MSIE" (<code>\b</code> means 158 "word boundary") in the <code>User-Agent</code> Header and turn off 159 the restrictions defined before.</p> 160 161 <div class="note"><h3>Note</h3> 162 The <code>DEFLATE</code> filter is always inserted after RESOURCE 163 filters like PHP or SSI. It never touches internal subrequests. 164 </div> 165 <div class="note"><h3>Note</h3> 166 There is a environment variable <code>force-gzip</code>, 167 set via <code class="directive"><a href="/mod/mod_env.html#setenv">SetEnv</a></code>, which 168 will ignore the accept-encoding setting of your browser and will 169 send compressed output. 170 </div> 171 172 173 <h3><a name="inflate" id="inflate">Output Decompression</a></h3> 174 <p>The <code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code> module also provides a filter for 175 inflating/uncompressing a gzip compressed response body. In order to activate 176 this feature you have to insert the <code>INFLATE</code> filter into 177 the outputfilter chain using <code class="directive"><a href="/mod/core.html#setoutputfilter">SetOutputFilter</a></code> or <code class="directive"><a href="/mod/mod_mime.html#addoutputfilter">AddOutputFilter</a></code>, for example:</p> 178 179 <div class="example"><p><code> 180 <Location /dav-area><br /> 181 <span class="indent"> 182 ProxyPass http://example.com/<br /> 183 SetOutputFilter INFLATE<br /> 184 </span> 185 </Location> 186 </code></p></div> 187 188 <p>This Example will uncompress gzip'ed output from example.com, so other 189 filters can do further processing with it. 190 </p> 191 192 193 <h3><a name="input" id="input">Input Decompression</a></h3> 194 <p>The <code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code> module also provides a filter for 195 decompressing a gzip compressed request body . In order to activate 196 this feature you have to insert the <code>DEFLATE</code> filter into 197 the input filter chain using <code class="directive"><a href="/mod/core.html#setinputfilter">SetInputFilter</a></code> or <code class="directive"><a href="/mod/mod_mime.html#addinputfilter">AddInputFilter</a></code>, for example:</p> 198 199 <div class="example"><p><code> 200 <Location /dav-area><br /> 201 <span class="indent"> 202 SetInputFilter DEFLATE<br /> 203 </span> 204 </Location> 205 </code></p></div> 206 207 <p>Now if a request contains a <code>Content-Encoding: 208 gzip</code> header, the body will be automatically decompressed. 209 Few browsers have the ability to gzip request bodies. However, 210 some special applications actually do support request 211 compression, for instance some <a href="http://www.webdav.org">WebDAV</a> clients.</p> 212 213 <div class="warning"><h3>Note on Content-Length</h3> 214 <p>If you evaluate the request body yourself, <em>don't trust 215 the <code>Content-Length</code> header!</em> 216 The Content-Length header reflects the length of the 217 incoming data from the client and <em>not</em> the byte count of 218 the decompressed data stream.</p> 219 </div> 220 221</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 222<div class="section"> 223<h2><a name="proxies" id="proxies">Dealing with proxy servers</a></h2> 224 225 <p>The <code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code> module sends a <code>Vary: 226 Accept-Encoding</code> HTTP response header to alert proxies that 227 a cached response should be sent only to clients that send the 228 appropriate <code>Accept-Encoding</code> request header. This 229 prevents compressed content from being sent to a client that will 230 not understand it.</p> 231 232 <p>If you use some special exclusions dependent 233 on, for example, the <code>User-Agent</code> header, you must 234 manually configure an addition to the <code>Vary</code> header 235 to alert proxies of the additional restrictions. For example, 236 in a typical configuration where the addition of the <code>DEFLATE</code> 237 filter depends on the <code>User-Agent</code>, you should add:</p> 238 239 <div class="example"><p><code> 240 Header append Vary User-Agent 241 </code></p></div> 242 243 <p>If your decision about compression depends on other information 244 than request headers (<em>e.g.</em> HTTP version), you have to set the 245 <code>Vary</code> header to the value <code>*</code>. This prevents 246 compliant proxies from caching entirely.</p> 247 248 <div class="example"><h3>Example</h3><p><code> 249 Header set Vary * 250 </code></p></div> 251</div> 252<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 253<div class="directive-section"><h2><a name="DeflateBufferSize" id="DeflateBufferSize">DeflateBufferSize</a> <a name="deflatebuffersize" id="deflatebuffersize">Directive</a></h2> 254<table class="directive"> 255<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Fragment size to be compressed at one time by zlib</td></tr> 256<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DeflateBufferSize <var>value</var></code></td></tr> 257<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>DeflateBufferSize 8096</code></td></tr> 258<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 259<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 260<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_deflate</td></tr> 261</table> 262 <p>The <code class="directive">DeflateBufferSize</code> directive specifies 263 the size in bytes of the fragments that zlib should compress at one 264 time.</p> 265 266</div> 267<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 268<div class="directive-section"><h2><a name="DeflateCompressionLevel" id="DeflateCompressionLevel">DeflateCompressionLevel</a> <a name="deflatecompressionlevel" id="deflatecompressionlevel">Directive</a></h2> 269<table class="directive"> 270<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>How much compression do we apply to the output</td></tr> 271<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DeflateCompressionLevel <var>value</var></code></td></tr> 272<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>Zlib's default</code></td></tr> 273<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 274<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 275<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_deflate</td></tr> 276<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>This directive is available since Apache 2.0.45</td></tr> 277</table> 278 <p>The <code class="directive">DeflateCompressionLevel</code> directive specifies 279 what level of compression should be used, the higher the value, 280 the better the compression, but the more CPU time is required to 281 achieve this.</p> 282 <p>The value must between 1 (less compression) and 9 (more compression).</p> 283 284</div> 285<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 286<div class="directive-section"><h2><a name="DeflateFilterNote" id="DeflateFilterNote">DeflateFilterNote</a> <a name="deflatefilternote" id="deflatefilternote">Directive</a></h2> 287<table class="directive"> 288<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Places the compression ratio in a note for logging</td></tr> 289<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DeflateFilterNote [<var>type</var>] <var>notename</var></code></td></tr> 290<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 291<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 292<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_deflate</td></tr> 293<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td><var>type</var> is available since Apache 2.0.45</td></tr> 294</table> 295 <p>The <code class="directive">DeflateFilterNote</code> directive 296 specifies that a note about compression ratios should be attached 297 to the request. The name of the note is the value specified for 298 the directive. You can use that note for statistical purposes by 299 adding the value to your <a href="/logs.html#accesslog">access log</a>.</p> 300 301 <div class="example"><h3>Example</h3><p><code> 302 DeflateFilterNote ratio<br /> 303 <br /> 304 LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate<br /> 305 CustomLog logs/deflate_log deflate 306 </code></p></div> 307 308 <p>If you want to extract more accurate values from your logs, you 309 can use the <var>type</var> argument to specify the type of data 310 left as note for logging. <var>type</var> can be one of:</p> 311 312 <dl> 313 <dt><code>Input</code></dt> 314 <dd>Store the byte count of the filter's input stream in the note.</dd> 315 316 <dt><code>Output</code></dt> 317 <dd>Store the byte count of the filter's output stream in the note.</dd> 318 319 <dt><code>Ratio</code></dt> 320 <dd>Store the compression ratio (<code>output/input * 100</code>) 321 in the note. This is the default, if the <var>type</var> argument 322 is omitted.</dd> 323 </dl> 324 325 <p>Thus you may log it this way:</p> 326 327 <div class="example"><h3>Accurate Logging</h3><p><code> 328 DeflateFilterNote Input instream<br /> 329 DeflateFilterNote Output outstream<br /> 330 DeflateFilterNote Ratio ratio<br /> 331 <br /> 332 LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate<br /> 333 CustomLog logs/deflate_log deflate 334 </code></p></div> 335 336<h3>See also</h3> 337<ul> 338<li><code class="module"><a href="/mod/mod_log_config.html">mod_log_config</a></code></li> 339</ul> 340</div> 341<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 342<div class="directive-section"><h2><a name="DeflateMemLevel" id="DeflateMemLevel">DeflateMemLevel</a> <a name="deflatememlevel" id="deflatememlevel">Directive</a></h2> 343<table class="directive"> 344<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>How much memory should be used by zlib for compression</td></tr> 345<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DeflateMemLevel <var>value</var></code></td></tr> 346<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>DeflateMemLevel 9</code></td></tr> 347<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 348<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 349<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_deflate</td></tr> 350</table> 351 <p>The <code class="directive">DeflateMemLevel</code> directive specifies 352 how much memory should be used by zlib for compression 353 (a value between 1 and 9).</p> 354 355</div> 356<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 357<div class="directive-section"><h2><a name="DeflateWindowSize" id="DeflateWindowSize">DeflateWindowSize</a> <a name="deflatewindowsize" id="deflatewindowsize">Directive</a></h2> 358<table class="directive"> 359<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Zlib compression window size</td></tr> 360<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DeflateWindowSize <var>value</var></code></td></tr> 361<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>DeflateWindowSize 15</code></td></tr> 362<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 363<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 364<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_deflate</td></tr> 365</table> 366 <p>The <code class="directive">DeflateWindowSize</code> directive specifies the 367 zlib compression window size (a value between 1 and 15). Generally, the 368 higher the window size, the higher can the compression ratio be expected.</p> 369 370</div> 371</div> 372<div class="bottomlang"> 373<p><span>Available Languages: </span><a href="/en/mod/mod_deflate.html" title="English"> en </a> | 374<a href="/ja/mod/mod_deflate.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 375<a href="/ko/mod/mod_deflate.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p> 376</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 377<script type="text/javascript"><!--//--><![CDATA[//><!-- 378var comments_shortname = 'httpd'; 379var comments_identifier = 'http://httpd.apache.org/docs/2.2/mod/mod_deflate.html'; 380(function(w, d) { 381 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 382 d.write('<div id="comments_thread"><\/div>'); 383 var s = d.createElement('script'); 384 s.type = 'text/javascript'; 385 s.async = true; 386 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 387 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 388 } 389 else { 390 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 391 } 392})(window, document); 393//--><!]]></script></div><div id="footer"> 394<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 395<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 396if (typeof(prettyPrint) !== 'undefined') { 397 prettyPrint(); 398} 399//--><!]]></script> 400</body></html>