]> granicus.if.org Git - apache/blobdiff - docs/manual/mod/mod_deflate.xml
Merge in APR[-util] macros from branches/trunk-buildconf-noapr
[apache] / docs / manual / mod / mod_deflate.xml
index b4774099fd1a8fd3bc8cf4a736ac7cba30d4a57d..0dfe511070f59eed5aee8b27f8a4813f47307b07 100644 (file)
@@ -37,6 +37,14 @@ client</description>
 </summary>
 <seealso><a href="../filter.html">Filters</a></seealso>
 
+<section id="supportedencodings"><title>Supported Encodings</title>
+  <p>The <code>gzip</code> encoding is the only one supported to ensure complete compatibility
+  with old browser implementations. The <code>deflate</code> encoding is not supported, 
+  please check the <a href="http://www.gzip.org/zlib/zlib_faq.html#faq38">zlib's documentation</a>
+  for a complete explanation.
+  </p>
+</section>
+
 <section id="recommended"><title>Sample Configurations</title>
     <note type="warning"><title>Compression and TLS</title>
         <p>Some web applications are vulnerable to an information disclosure
@@ -68,7 +76,7 @@ client</description>
 
       <highlight language="config">
 SetOutputFilter DEFLATE
-SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip 
+SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
       </highlight>
 
       <p>If you want to restrict the compression to particular MIME types
@@ -88,7 +96,7 @@ SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
         filters like PHP or SSI. It never touches internal subrequests.
       </note>
       <note><title>Note</title>
-        There is a environment variable <code>force-gzip</code>,
+        There is an environment variable <code>force-gzip</code>,
         set via <directive module="mod_env">SetEnv</directive>, which
         will ignore the accept-encoding setting of your browser and will
         send compressed output.
@@ -99,13 +107,13 @@ SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
       <p>The <module>mod_deflate</module> module also provides a filter for
       inflating/uncompressing a gzip compressed response body. In order to activate
       this feature you have to insert the <code>INFLATE</code> filter into
-      the outputfilter chain using <directive module="core"
+      the output filter chain using <directive module="core"
       >SetOutputFilter</directive> or <directive module="mod_mime"
       >AddOutputFilter</directive>, for example:</p>
 
       <highlight language="config">
-&lt;Location /dav-area&gt;
-    ProxyPass http://example.com/
+&lt;Location "/dav-area"&gt;
+    ProxyPass "http://example.com/"
     SetOutputFilter INFLATE
 &lt;/Location&gt;
       </highlight>
@@ -124,7 +132,7 @@ SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
       >AddInputFilter</directive>, for example:</p>
 
       <highlight language="config">
-&lt;Location /dav-area&gt;
+&lt;Location "/dav-area"&gt;
     SetInputFilter DEFLATE
 &lt;/Location&gt;
       </highlight>
@@ -178,6 +186,48 @@ SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
     </example>
 </section>
 
+<section id="precompressed"><title>Serving pre-compressed
+content</title>
+
+    <p>Since <module>mod_deflate</module> re-compresses content each
+    time a request is made, some performance benefit can be derived by
+    pre-compressing the content and telling mod_deflate to serve them
+    without re-compressing them. This may be accomplished using a
+    configuration like the following:</p>
+
+    <highlight language="config">
+&lt;IfModule mod_headers.c&gt;
+    # Serve gzip compressed CSS files if they exist
+    # and the client accepts gzip.
+    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
+    RewriteCond "%{REQUEST_FILENAME}\.gz" "-s"
+    RewriteRule "^(.*)\.css"              "$1\.css\.gz" [QSA]
+
+    # Serve gzip compressed JS files if they exist
+    # and the client accepts gzip.
+    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
+    RewriteCond "%{REQUEST_FILENAME}\.gz" "-s"
+    RewriteRule "^(.*)\.js"               "$1\.js\.gz" [QSA]
+
+
+    # Serve correct content types, and prevent mod_deflate double gzip.
+    RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
+    RewriteRule "\.js\.gz$"  "-" [T=text/javascript,E=no-gzip:1]
+
+
+    &lt;FilesMatch "(\.js\.gz|\.css\.gz)$"&gt;
+      # Serve correct encoding type.
+      Header append Content-Encoding gzip
+
+      # Force proxies to cache gzipped &amp;
+      # non-gzipped css/js files separately.
+      Header append Vary Accept-Encoding
+    &lt;/FilesMatch&gt;
+&lt;/IfModule&gt;
+    </highlight>
+
+</section>
+
 <directivesynopsis>
 <name>DeflateFilterNote</name>
 <description>Places the compression ratio in a note for logging</description>
@@ -196,15 +246,15 @@ SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
     <example><title>Example</title>
     <highlight language="config">
       DeflateFilterNote ratio
-    
+
       LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate
-      CustomLog logs/deflate_log deflate
+      CustomLog "logs/deflate_log" deflate
       </highlight>
     </example>
 
     <p>If you want to extract more accurate values from your logs, you
     can use the <var>type</var> argument to specify the type of data
-    left as note for logging. <var>type</var> can be one of:</p>
+    left as note for logging. <var>type</var> can be one of:</p>
 
     <dl>
       <dt><code>Input</code></dt>
@@ -228,7 +278,7 @@ DeflateFilterNote Output outstream
 DeflateFilterNote Ratio ratio
 
 LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
-CustomLog logs/deflate_log deflate
+CustomLog "logs/deflate_log" deflate
 </highlight>
     </example>
 </usage>
@@ -246,7 +296,14 @@ CustomLog logs/deflate_log deflate
 <usage>
     <p>The <directive>DeflateBufferSize</directive> directive specifies
     the size in bytes of the fragments that zlib should compress at one
-    time.</p>
+    time. If the compressed response size is bigger than the one specified
+    by this directive then httpd will switch to chunked encoding 
+    (HTTP header <code>Transfer-Encoding</code> set to <code>Chunked</code>), with the
+    side effect of not setting any <code>Content-Length</code> HTTP header. This is particularly 
+    important when httpd works behind reverse caching proxies or when httpd is configured with 
+    <module>mod_cache</module> and <module>mod_cache_disk</module> because
+    HTTP responses without any <code>Content-Length</code> header might not be cached.
+  </p>
 </usage>
 </directivesynopsis>
 
@@ -311,18 +368,18 @@ CustomLog logs/deflate_log deflate
     how the ETag hader should be altered when a response is compressed.</p>
     <dl>
     <dt>AddSuffix</dt>
-    <dd><p>Append the compression method onto the end of the ETag, causing 
-        compressed and uncompressed representatins to have unique ETags.  
-        This has been the default since 2.4.0, but prevents serving 
-        "HTTP Not Modified" (304) responses to conditional requests for 
+    <dd><p>Append the compression method onto the end of the ETag, causing
+        compressed and uncompressed representations to have unique ETags.
+        This has been the default since 2.4.0, but prevents serving
+        "HTTP Not Modified" (304) responses to conditional requests for
         compressed content.</p></dd>
     <dt>NoChange</dt>
     <dd><p>Don't change the ETag on a compressed response. This was the default
         prior to 2.4.0, but does not satisfy the HTTP/1.1 property that all
-        representations of the same resource have unique ETags </p></dd>
+        representations of the same resource have unique ETags. </p></dd>
     <dt>Remove</dt>
-    <dd><p>Remove the ETag header from compressed responses. This prevents 
-        some conditional requests from being possible, but avoids the 
+    <dd><p>Remove the ETag header from compressed responses. This prevents
+        some conditional requests from being possible, but avoids the
         shortcomings of the preceding options.  </p></dd>
     </dl>
 </usage>
@@ -335,10 +392,11 @@ CustomLog logs/deflate_log deflate
 <default>None, but LimitRequestBody applies after deflation</default>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context><context>.htaccess</context></contextlist>
+<override>All</override>
 <compatibility>2.4.10 and later</compatibility>
 
 <usage>
-    <p>The <directive>DeflateInflateLimitRequestBody</directive> directive 
+    <p>The <directive>DeflateInflateLimitRequestBody</directive> directive
         specifies the maximum size of an inflated request body. If it is unset,
         <directive module="core">LimitRequestBody</directive> is applied to the
         inflated body.</p>
@@ -352,35 +410,36 @@ CustomLog logs/deflate_log deflate
 <default>200</default>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context><context>.htaccess</context></contextlist>
+<override>All</override>
 <compatibility>2.4.10 and later</compatibility>
 
 <usage>
-    <p>The <directive>DeflateInflateRatioLimit</directive> directive 
-        specifies the maximum ratio of deflated to inflated size of an 
+    <p>The <directive>DeflateInflateRatioLimit</directive> 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 
-        <directive>DeflateInflateRatioBurst</directive> times the request
+        streamed in, and if crossed more than
+        <directive>DeflateInflateRatioBurst</directive> times, the request
         will be terminated.</p>
 </usage>
 </directivesynopsis>
 
 <directivesynopsis>
 <name>DeflateInflateRatioBurst</name>
-<description>Maximum number of times the inflation ratio for request bodies 
+<description>Maximum number of times the inflation ratio for request bodies
              can be crossed</description>
 <syntax>DeflateInflateRatioBurst <var>value</var></syntax>
 <default>3</default>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context><context>.htaccess</context></contextlist>
+<override>All</override>
 <compatibility>2.4.10 and later</compatibility>
 
 <usage>
-    <p>The <directive>DeflateInflateRatioBurst</directive> directive 
-       specifies the maximum number of times the 
-       <directive>DeflateInflateRatioLimit</directive> cab be crossed before 
+    <p>The <directive>DeflateInflateRatioBurst</directive> directive
+       specifies the maximum number of times the
+       <directive>DeflateInflateRatioLimit</directive> can be crossed before
        terminating the request.</p>
 </usage>
 </directivesynopsis>
 
 </modulesynopsis>
-