xref: /lighttpd1.4/doc/outdated/compress.txt (revision dab212b5)
1==================
2Output Compression
3==================
4
5--------------------
6Module: mod_compress
7--------------------
8
9
10.. meta::
11  :keywords: lighttpd, compress
12
13.. contents:: Table of Contents
14
15WARNING
16=======
17
18mod_compress has been subsumed by mod_deflate.
19
20Description
21===========
22
23Output compression reduces the network load and can improve the overall
24throughput of the webserver. All major http-clients support compression by
25announcing it in the Accept-Encoding header. This is used to negotiate the
26most suitable compression method. We support deflate, gzip and bzip2.
27
28deflate (RFC1950, RFC1951) and gzip (RFC1952) depend on zlib while bzip2
29depends on libbzip2. bzip2 is only supported by lynx and some other console
30text-browsers.
31
32We currently limit to compression support to static files.
33
34Caching
35-------
36
37mod_compress can store compressed files on disk to optimize the compression
38on a second request away. As soon as compress.cache-dir is set the files are
39compressed.
40
41(You will need to create the cache directory if it doesn't already exist. The web server will not do this for you.  The directory will also need the proper ownership.  For Debian/Ubuntu the user and group ids should both be www-data.)
42
43The names of the cache files are made of the filename, the compression method
44and the etag associated to the file.
45
46Cleaning the cache is left to the user. A cron job deleting files older than
4710 days could do it: ::
48
49  find /var/www/cache -type f -mtime +10 | xargs -r rm
50
51Limitations
52-----------
53
54The module limits the compression of files to files smaller than 128 MByte and
55larger than 128 Byte.
56
57The lower limit is set as small files tend to become larger by compressing due
58to the compression headers, the upper limit is set to work sensibly with
59memory and cpu-time.
60
61Directories containing a tilde ('~') are not created automatically (See ticket
62#113). To enable compression for user dirs you have to create the directories
63by hand in the cache directory.
64
65Options
66=======
67
68compress.allowed-encodings
69  override default set of allowed encodings
70
71  e.g.: ::
72
73    compress.allowed-encodings = ("bzip2", "gzip", "deflate")
74
75compress.cache-dir
76  name of the directory where compressed content will be cached
77
78  e.g.: ::
79
80    compress.cache-dir = "/var/www/cache/"
81
82    # even better with virt-hosting
83    $HTTP["host"] == "docs.example.org" {
84      compress.cache-dir = "/var/www/cache/docs.example.org/"
85    }
86
87  Default: not set, compress the file for every request
88
89compress.filetype
90  mimetypes which might get compressed
91
92  e.g.: ::
93
94    compress.filetype           = ("text/plain", "text/html")
95
96  Keep in mind that compressed JavaScript and CSS files are broken in some
97  browsers. Not setting any filetypes will result in no files being compressed.
98
99  NOTE: You have to specify the full mime-type! If you also define a charset, for example, you have to use "text/plain; charset=utf-8" instead of just "text/plain".
100
101  Default: not set
102
103compress.max-filesize
104  maximum size of the original file to be compressed kBytes.
105
106  This is meant to protect the server against DoSing as compressing large
107  (let's say 1Gbyte) takes a lot of time and would delay the whole operation
108  of the server.
109
110  There is a hard upper limit of 128Mbyte.
111
112  Default: unlimited (== hard-limit of 128MByte)
113
114Display compressed files
115========================
116
117If you enable mod_compress, and you want to force clients to uncompress and display compressed text files, please force mimetype to nothing.
118Example :
119If you want to add headers for uncompress and display diff.gz files , add this section in your conf : ::
120
121  $HTTP["url"] =~ "\.diff\.gz" {
122    setenv.add-response-header = ( "Content-Encoding" => "gzip" )
123    mimetype.assign = ()
124  }
125
126
127Compressing Dynamic Content
128===========================
129
130PHP
131---
132
133To compress dynamic content with PHP please enable ::
134
135  zlib.output_compression = 1
136  zlib.output_handler = On
137
138in the php.ini as PHP provides compression support by itself.
139
140mod_compress of lighttpd 1.5 r1992 may not set correct Content-Encoding with php-fcgi. A solution to that problem would be:
141
1421.disable mod_compress when request a php file::
143
144    $HTTP["url"] !~ "\.php$" {
145    	compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml")
146    }
147
1482.enable mod_setenv of your lighttpd::
149
150    server.modules  += ( "mod_setenv" )
151
1523.manually set Content-Encoding::
153
154    $HTTP["url"] =~ "\.php$" {
155  	setenv.add-response-header  = ( "Content-Encoding" => "gzip")
156    }
157
158
159TurboGears
160----------
161
162To compress dynamic content with TurboGears please enable ::
163
164  [/]
165  gzip_filter.on = True
166  gzip_filter.mime_types = ["application/x-javascript", "text/javascript", "text/html", "text/css", "text/plain"]
167
168in the config/app.cfg file in your TurboGears application.  The above lines should already be in the file.  You just need to remove the comment symbol in front of the lines to make them active.
169
170Django
171------
172
173To compress dynamic content with Django please enable the GZipMiddleware ::
174
175  MIDDLEWARE_CLASSES = (
176      'django.middleware.gzip.GZipMiddleware',
177      ...
178  )
179
180in the settings.py file in your Django project.
181
182Catalyst
183--------
184
185To compress dynamic content with Perl/Catalyst, simply use the Catalyst::Plugin::Compress::Gzip module available on CPAN ::
186
187  use Catalyst qw(
188      Compress::Gzip
189      ...
190  );
191
192in your main package (MyApp.pm). Further configuration is not required.
193
194}}}
195
196
197
198