A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.
1 <?xml version="1.0" encoding="iso-8859-1" ?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 5 <head> 6 <title>An example configuration for mod_gzip</title> 7 <meta name="author" content="Michael Schröpl" /> 8 <meta name="description" content="An extensively documented example configuration for the Apache add-on module 'mod_gzip'" /> 9 <meta name="keywords" content="Apache, HTTP, encoding, gzip, compression, configuration" /> 10 <style type="text/css"> 11 body{font-family:sans-serif;margin:0px 30px 0px 30px;} 12 h1{font-size:22px;margin-top:20px;} 13 h2{font-size:18px;margin-top:14px;} 14 small{font-size:80%;} 15 td{vertical-align:top;} 16 tt{font-weight:bold;} 17 code,tt{font-family:"Courier New",monospace;} 18 h1,h2{margin-bottom:1px;} 19 p,td{margin-top:3px;margin-bottom:3px;} 20 p,ul,ol,li{font-size:17px;line-height:22px;} 21 ul,ol,li{margin-top:0px;margin-bottom:0px;} 22 img{border-width:0;} 23 24 #nav{position:absolute;top:30px;left:0px;font-size:14px;width:170px;font-weight:bold;margin:2px 2px 2px 30px;} 25 #nav[id]{position:fixed;} 26 #nav img{margin:5px;} 27 #nav p, #nav a:hover, #nav a{display:block;padding:3px;margin:2px;width:150px;font-size:15px;line-height:18px;} 28 #content{position:absolute;left:220px;right:30px;} 29 #mail{text-align:right;} 30 #icon{width:190px;float:left;} 31 #mail,#icon{margin-top:30px;} 32 33 @media screen { 34 body{color:#000;background-color:#f8ebd9;} 35 h1{color:#666;} 36 h2{color:#840;} 37 code{color:#333;} 38 em{color:#900;} 39 tt{color:#909;} 40 h1,h2,code,em,tt{background-color:inherit;} 41 .new13192a{color:#inherit;background-color:#ffd;} 42 .new13261a{color:#inherit;background-color:#eff;} 43 .bugfix{color:#fff;background-color:#f00;font-weight:bold;padding:0px 4px;} 44 #nav a{color:#530;background-color:transparent;} 45 #nav a{text-decoration:none;} 46 #nav p, #nav a:hover{color:#000;background-color:#fff;} 47 #nav p {border:1px #660 solid;} 48 #nav a {border:1px #666 dotted;} 49 } 50 51 @media print { 52 #icon,#nav{display:none;} 53 #content{position:absolute;left:0px;right:0px;} 54 } 55 table.sections{margin-top:20px;} 56 table.sections td{border:solid 1px #55f;font-size:12px;padding:2px;} 57 table.sections td a{display:block;} 58 59 @screen { 60 table.sections td{color:#000;background-color:#eee;} 61 table.sections td a{color:#00f;background-color:transparent;} 62 } 63 pre{font-family:monospace;font-size:14px;} 64 pre strong{font-weight:bold;} 65 66 @media screen { 67 pre{color:#336;} 68 pre strong{color:#00c;} 69 pre, pre strong{background-color:inherit;} 70 } 71 </style> 72 </head> 73 74 <body> 75 76 <div id="nav"> 77 78 <img src="mod_gzip_logo.gif" height="47" width="102" alt="mod_gzip logo" /> 79 80 81 <a title="mod_gzip - what's that, anyway?" href="index.htm">mod_gzip</a> 82 83 84 85 <a title="Compression of HTTP content using Content-Encoding" href="encoding.htm">Content-Encoding</a> 86 87 88 89 <a title="Which browsers can handle 'Content-Encoding: gzip'?" href="browser.htm">Browsers</a> 90 91 92 93 <a title="How do Firewalls handle 'Content-Encoding:'?" href="firewalls.htm">Firewalls</a> 94 95 96 97 <p>Configuration</p> 98 99 100 101 <a title="Complete description of mod_gzip status codes" href="status.htm">Status Codes</a> 102 103 104 105 <a title="Possible enhancements in future versions of mod_gzip" href="enhancements.htm">Enhancements</a> 106 107 108 109 <a title="Caching of negotiated HTTP responses" href="cache.htm">Caching</a> 110 111 112 113 <a title="Version history and change log for mod_gzip" href="versions.htm">Versions</a> 114 115 116 117 <a title="Other ressources about mod_gzip" href="links.htm">Links</a> 118 119 120 </div> 121 122 <div id="content"> 123 124 <h1>An example configuration for <tt>mod_gzip</tt></h1> 125 126 <p>The exact amount of the requested functions is to be described by additional <em>Apache configuration directives</em> which become available by the <tt>mod_gzip</tt> module integration.</p> 127 <p>A really complete documentation of the effect of these directives isn't available at the moment; in general assume that</p> 128 <ul> 129 <li>about everything can be used in every environment, i. e. 130 <ul> 131 <li>in the complete server scope,</li> 132 <li>in separate virtual hosts,</li> 133 <li>in directories or even</li> 134 <li>in <code>.htaccess</code> files</li> 135 </ul> and 136 </li> 137 <li>basically the standard overwriting procedures of Apache apply - except for the directives to specify the selection of contents to be compressed, where things become a bit more complicated.</li> 138 </ul> 139 <p>The configuration described below really <em>isn't</em> meant for blindly copying into your own configuration - its intention rather is to give you a feeling about how many options are provided. And there are <em>lots</em> of options - at least if you 'just want to get compressed output data' ...</p> 140 141 <table class="sections"> 142 <tr> 143 <td><a href="#loading">loading</a></td> 144 <td><a href="#responsibilities">responsibilities</a></td> 145 <td><div class="new13261a"><a href="#precompressed">precompressed</a></div></td> 146 <td><a href="#bureaucracy">bureaucracy</a></td> 147 <td><a href="#data_management">data management</a></td> 148 <td><a href="#file_sizes">file sizes</a></td> 149 <td><div class="new13261a"><a href="#requirements">requirements</a></div></td> 150 <td><a href="#filters">filters</a></td> 151 <td><a href="#transfer_encoding">transfer encoding</a></td> 152 <td><a href="#logging">logging</a></td> 153 <td><div class="new13192a"><a href="#proxy">proxies</a></div></td> 154 </tr> 155 </table> 156 157 <pre> 158 ####################################### 159 ### Apache configuration directives ### 160 ### for mod_gzip 1.3.26.1a ### 161 ####################################### 162 <a id="loading"></a> 163 ########################## 164 ### loading the module ### 165 ########################## 166 167 # --------------------------------------------------------------------- 168 # load DLL / Win32: 169 # LoadModule gzip_module modules/ApacheModuleGzip.dll 170 # 171 # load DSO / UNIX: 172 # LoadModule gzip_module modules/mod_gzip.so 173 # 174 # (none of both if module has been compiled in statically; 175 <div class="new13192a"># the exact file name may depend upon the exact compilation method used 176 # for this module) 177 </div># --------------------------------------------------------------------- 178 179 <strong><IfModule mod_gzip.c></strong> 180 <a id="responsibilities"></a> 181 ######################## 182 ### responsibilities ### 183 ######################## 184 185 # --------------------------------------------------------------------- 186 # use mod_gzip at all? 187 <strong>mod_gzip_on Yes</strong> 188 # (you can especially enable mod_gzip inside the central server 189 # configuration but disable it inside some directories ot virtual 190 # hosts by using this directive.) 191 # --------------------------------------------------------------------- 192 <a id="precompressed"></a> 193 ###################################### 194 ### statically precompressed files ### 195 ###################################### 196 197 # --------------------------------------------------------------------- 198 # let mod_gzip perform 'partial content negotiation'? 199 <strong>mod_gzip_can_negotiate Yes</strong> 200 # (if this option is active and a static file is to be served in com- 201 # pressed for, then mod_gzip will look for a static precompressed 202 # version of this file with a defined additional extension - see next 203 # directive - which would be delivered with priority. This would allow 204 # for avoiding to repeatedly compress the same static file and thus 205 # saving CPU time. 206 # No dynamic caching of this file is provided; currently the user 207 # himself is responsible for creating and updating the precompressed 208 # file's content. 209 <div class="new13192a"># From version 1.3.19.2a mod_gzip automatically recognizes whether 210 # a statically precompressed file is older than its uncompressed 211 # original and in this case will serve the content of the original 212 # file in uncompressed form - as to rather serve correct data than 213 # outdated ones ...) 214 </div># --------------------------------------------------------------------- 215 <div class="new13192a"># extension (suffix) for statically precompressed files 216 <strong>mod_gzip_static_suffix .gz</strong> 217 <strong>AddEncoding gzip .gz</strong> 218 # (effect: see previous directive; this string will be appended to the 219 # name of the original file. 220 # be sure to configure the encoding 'gzip' for this extension as well, 221 # because mod_gzip doesn't serve the content itself but simply generates 222 # an Apache internal redirection to this URL. Therefore the remaining 223 # Apache configuration is responsible for setting the 'Content-Encoding' 224 # header properly ... 225 # prior to version 1.3.19.2a this value was not configurable.) 226 </div># --------------------------------------------------------------------- 227 <div class="new13261a"># automatic updates for statically precompressed files 228 <strong>mod_gzip_update_static No</strong> 229 # (if set to 'Yes', this directive (being new in version 1.3.26.1a) would 230 # cause mod_gzip to automatically update an outdated version of any 231 # statically precompressed file during the request, i. e. compress the 232 # originally requested file and <em>overwrite</em> the precompressed variant 233 # file with it! 234 # for each automatic update of this type, mod_gzip will write a message 235 # of the severity 'notice' into the Apache error_log. 236 # while doing so, mod_gzip will directly read the original file's content. 237 # therefore this content <em>cannot</em> be interpreted by any other Apache module 238 # during the request. this might possibly <em>not</em> be what you want - hopefully 239 # it will be what most users want, because it works <em>fast</em> this way. 240 # use this configuration with a lot of care, and be sure that you don't 241 # inadvertantly cause valuable files within the URL tree to be overwritten. 242 # this <em>isn't</em> a feature to be used for mass hosting servers, especially 243 # because mod_gzip might experience access control problems there - the 244 # userid the Apache processes are running under need to have write access 245 # to the precompressed files of all users, which may not automatically be 246 # the case.) 247 # [mod_gzip error handling in this situation??? what will be served?] 248 </div># --------------------------------------------------------------------- 249 <a id="bureaucracy"></a> 250 ################### 251 ### bureaucracy ### 252 ################### 253 254 # --------------------------------------------------------------------- 255 # display status for mod_gzip 256 <strong>mod_gzip_command_version '/mod_gzip_status'</strong> 257 # (defines an URL to display the status of mod_gzip; can be specified 258 # individually for each installation and protected against access via 259 # <Location> section for privacy reasons) 260 # --------------------------------------------------------------------- 261 # The status display will look like this: 262 # mod_gzip is available... 263 # mod_gzip_version = 1.3.26.1a 264 # mod_gzip_on = Yes/No 265 # and thus will provide information about 266 # - mod_gzip being installed at the server and working correctly, 267 # - which version has been installed and 268 # - whether mod_gzip has been set 'active' for this Location 269 # (-> mod_gzip_on) 270 # --------------------------------------------------------------------- 271 <a id="data_management"></a> 272 ####################### 273 ### data management ### 274 ####################### 275 276 # --------------------------------------------------------------------- 277 # Working directory for temporary files and the compression cache 278 # if not specified, the following default values are used: 279 # [Win32=c:\temp], [UNIX=/tmp] 280 # <strong>mod_gzip_temp_dir /tmp</strong> 281 # (This directory must already exist and the userid being used for 282 # running the Apache server must have read and write access to this 283 # directory. 284 # Unlike other Apache directives an absolute path name must be specified 285 # here; a relative value will not be interpreted relatively to ServerRoot. 286 # This pastname must NOT be terminated with '/'. 287 # For maximum performance this directory should be located on a RAM disk, 288 # if the file system isn't already being cached efficiently 289 # --------------------------------------------------------------------- 290 # Save temporary work files [Yes, No] 291 <strong>mod_gzip_keep_workfiles No</strong> 292 # (one file per HTTP request - set to 'yes' for debugging purpose only!) 293 # --------------------------------------------------------------------- 294 <a id="file_sizes"></a> 295 ################## 296 ### file sizes ### 297 ################## 298 299 # --------------------------------------------------------------------- 300 # minimum size (in bytes) for files to be compressed 301 <strong>mod_gzip_minimum_file_size 500</strong> 302 # (for very small files compression will produce only small absolute gains 303 # [you will still save about 50% of the content, but some additional 304 # 500 bytes of HTTP and TCP headers will always remain uncompressed], 305 # but still produce CPU load for both client and server) 306 # --------------------------------------------------------------------- 307 # maximum size (in bytes) for files to be compressed 308 <strong>mod_gzip_maximum_file_size 500000</strong> 309 # (for very large files compression may eventually take rather long and 310 # thus delay the start of the transmission. 311 # Furthermode a limitation at this point prevents the server from 312 # producing output of unlimited size in case of some endless loop 313 # inside a CGI script - or even trying to compress streaming data - 314 # which might otherwise cause the creation of a temporary file of 315 # any size and even fill up the whole hard disk. 316 # On the other hand, compression will have a much more perceivable 317 # subjective effect for large files ... so be sure to fine-tune this 318 # according to your requirements.) 319 # --------------------------------------------------------------------- 320 # maximum size (in bytes) for files to be compressed in memory 321 <strong>mod_gzip_maximum_inmem_size 60000</strong> 322 # (larger files will be compressed into the temp file directory; adapt 323 # this value to your server's available main memory. 324 # In mod_gzip 1.3.19.x larger values will automatically be limited to 325 # 60000 because some operating systems are said to have problems 326 # allocating more than 64 kb of memory at a time. 327 # --------------------------------------------------------------------- 328 <a id="requirements"></a> 329 #################### 330 ### requirements ### 331 #################### 332 333 # (see chapter about <a href="cache.htm#vary-1.3.19.2a">caching</a> for problems when using these directives.) 334 # --------------------------------------------------------------------- 335 # Required HTTP version of the client 336 # Possible values: 1000 = HTTP/1.0, 1001 = HTTP/1.1, ... 337 # This directive uses the same numeric protocol values as Apache does 338 # internally 339 <strong>mod_gzip_min_http 1000</strong> 340 # (By using this directive you may exclude old browsers, search engines 341 # etc. from the compression procedure: if the user agent doesn't 342 # declare itself capable of understanding at least the HTTP level 343 # specified here, only uncompressed data will be delivered - no matter 344 # what else it claims to be able to. The value of '1001' will especially 345 # exclude Netscape 4.x. and a lot of proxy servers.) 346 # --------------------------------------------------------------------- 347 <div class="new13192a"># HTTP methods to be handled 348 # Possible values: 'GET', 'POST' or a list of both values. 349 <strong>mod_gzip_handle_methods GET POST</strong> 350 # (By using this directive you may particularly exclude POST requests 351 # from the compression procedure. There are known cases where the 352 # handling of these requests by previous mod_gzip versions could cause 353 # problems. 354 # Before version 1.3.19.2a this value was not configurable.) 355 </div># --------------------------------------------------------------------- 356 <a id="filters"></a> 357 ############### 358 ### filters ### 359 ############### 360 361 # --------------------------------------------------------------------- 362 # which files are to be compressed? 363 # 364 # The order of processing during each of both phases is not important, 365 # but to trigger the compression of a request's content this request 366 # a) <em>must match at least one include rule in each of both phases</em> and 367 # b) <em>must not match an exclude rule in any of both phases.</em> 368 # These rules are not minimal, they are meant to serve as example only. 369 # 370 # phase 1: (reqheader, uri, file, handler) 371 # ======================================== 372 # (see chapter about <a href="cache.htm#useragent">caching</a> for problems when using 'reqheader' type 373 # filter rules.) 374 # NO: special broken browsers which request for gzipped content 375 # but then aren't able to handle it correctly 376 <strong>mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"</strong> 377 # 378 # JA: HTML-Dokumente 379 <strong>mod_gzip_item_include file \.html$</strong> 380 # 381 # NO: include files / JavaScript & CSS (due to Netscape4 bugs) 382 <strong>mod_gzip_item_exclude file \.js$</strong> 383 <strong>mod_gzip_item_exclude file \.css$</strong> 384 # 385 # YES: CGI scripts 386 <strong>mod_gzip_item_include file \.pl$</strong> 387 <strong>mod_gzip_item_include handler ^cgi-script$</strong> 388 # 389 # phase 2: (mime, rspheader) 390 # =========================== 391 # YES: normal HTML files, normal text files, Apache directory listings 392 <strong>mod_gzip_item_include mime ^text/html$</strong> 393 <strong>mod_gzip_item_include mime ^text/plain$</strong> 394 <strong>mod_gzip_item_include mime ^httpd/unix-directory$</strong> 395 # 396 # NO: images (GIF etc., will rarely ever save anything) 397 <strong>mod_gzip_item_exclude mime ^image/</strong> 398 # --------------------------------------------------------------------- 399 # In fact mod_gzip is checking only the first 4 characters of the 1st 400 # operand (in case of <strong>uri</strong> even the first 2 characters only, as to 401 # allow for values like <strong>url</strong>). 402 # --------------------------------------------------------------------- 403 # The table for mod_gzip_item rules (<strong>include</strong> and <strong>exclude</strong>) cannot contain 404 # more than 256 entries; when this number is exceeded mod_gzip will 405 # output the message <cite>"mod_gzip: ERROR: Item index is full"</cite> 406 # and report a configuration error to the Apache server. 407 # --------------------------------------------------------------------- 408 # The directive values described here are meant to describe the requests 409 # elected for compression <em>most exactly</em>. 410 # Especially for the <strong>mime</strong> rules it has to be made clear that the HTTP 411 # header 'Content-Type' (that will be checked by mod_gzip for this rule) 412 # in some cases may contain not only a MIME type but additionally a 413 # character set description (charset) as well. 414 # If this is the case for the requests to be handled then you need to 415 # remove the '$' char at the end of the corresponding value so that now 416 # only the prefix of this value will be tested for matching. 417 # --------------------------------------------------------------------- 418 <a id="transfer_encoding"></a> 419 ########################## 420 ### transfer encodings ### 421 ########################## 422 423 # --------------------------------------------------------------------- 424 # Allow mod_gzip to eliminate the HTTP header 425 # 'Transfer-encoding: chunked' 426 # and join the chunks to one (compressable) packet 427 <strong>mod_gzip_dechunk Yes</strong> 428 # (this is required for handling several types of dynamically generated 429 # contents, especially for CGI and SSI pages, but also for pages produced 430 # by some Java Servlet interpreters. 431 # --------------------------------------------------------------------- 432 <a id="logging"></a> 433 ############### 434 ### logging ### 435 ############### 436 437 # --------------------------------------------------------------------- 438 # Extended log format (for testing the compression effect) 439 <strong>LogFormat "%h %l %u %t \"%V %r\" %<s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n -< Out:%{mod_gzip_output_size}n = %{mod_gzip_compression_ratio}n pct." common_with_mod_gzip_info2</strong> 440 # --------------------------------------------------------------------- 441 # Create additional log file 442 <strong>CustomLog logs/mod_gzip.log common_with_mod_gzip_info2</strong> 443 # (surely you can redefine your normal log file format, but you mal well 444 # keep its format standard compatible for evaluation by standard web 445 # analysis tools. So we just create another log file.) 446 # --------------------------------------------------------------------- 447 # Volume computation of the delivered files inside the Apache access_log: 448 # count HTTP header size (in bytes) as part of total output size 449 <strong>mod_gzip_add_header_count Yes</strong> 450 # (This will be more than the pure document content, but it will more 451 # realistically describe the total output traffic of the HTTP request) 452 # --------------------------------------------------------------------- 453 454 <a id="proxy"></a> 455 <div class="new13192a">############### 456 ### proxies ### 457 ############### 458 459 # --------------------------------------------------------------------- 460 # sending a 'Vary' HTTP header 461 <strong>mod_gzip_send_vary Yes</strong> 462 # (see chapter about <a href="cache.htm#vary-1.3.19.2a">caching</a> for this directive.) 463 # <em>don't change this unless you absolutely know what you are doing!</em> 464 # --------------------------------------------------------------------- 465 </div> 466 <strong></IfModule></strong> 467 </pre> 468 469 <p><a id="LoadModule"></a>When adding this module dynamically you have to keep in mind that <tt>mod_gzip</tt> should be specified as <em>last one</em> of several <code>LoadModule</code> directives to be used.</p> 470 <p>This is because Apache will internally build a stack from the <code>LoadModule</code> directives and later evaluate it <em>in reverse order</em>.</p> 471 <p><tt>mod_gzip</tt> hooks itself into the internal <code>type_checker</code> routine of Apache; but only the <em>first</em> of all modules declaring itself as responsible for handling of a request <small>(e. g. ColdFusion and SSL will try to)</small> will really be activated by Apache. So <tt>mod_gzip</tt> has to be activated <em>before</em> those modules whose output it wants to redirect into itself and then postprocess - as long as these modules try to use the same <code>type_checker</code> interface ... if they don't, then it <em>may</em> work independently from this order of directives.</p> 472 <p>During Apache's start message <small>(which can be found e. g. inside the Apache error log)</small> modules having individual version specifications may be listed exactly in the order they appear inside the module chain; there <tt>mod_gzip</tt> has to be listed <em>before</em> other modules whose output it is intended to compress.</p> 473 <p>I myself statically compiled <tt>mod_gzip</tt> inside the subdirectory <code>src/modules/extra/</code> of the Apache source code; the Apache configuration script <code>configure</code> just knows what to do in this case.</p> 474 475 <div id="icon"> 476 <a href="http://validator.w3.org/check/referer"><img alt="" title="valid XHTML 1.1" height="31" width="88" src="valid-xhtml11.png" /></a><a href="http://jigsaw.w3.org/css-validator/check/referer"><img alt="" title="valid CSS" height="31" width="88" src="valid-css.png" /></a> 477 </div> 478 479 480 <p id="mail">(<a href="mailto:michael.schroepl@gmx.de?subject=mod_gzip">Michael Schröpl</a>, 2002-09-30)</p> 481 482 </div> 483 484 </body> 485 </html>