BIP KB:
How To Add mod_compress: Lighttpd Gzip Compression To Improve Download And Browsing Speed
Article By yang-li
![]() |
Introductions to mod_compressGzip is the most popular and effective compression method. Most modern web browser supports and accepts compressed data transfer. By gziping response time can reduced by 60-70% as compare to normal web page. The end result is faster web site experience for both dial up (they're not dead yet - I've dial up account for backup purpose) and broadband user. I've already written about speeding up Apache 2.x web access or downloads with mod_deflate. Now check out mod_compress. |
mod_compress For Lighttpd 1.4.xx
Lighttpd 1.4.xx supports gzip compression using mod_compress. This module can reduces the network load and can improve the overall throughput of the webserver. All major http-clients support compression by announcing it in the Accept-Encoding header as follows:Accept-Encoding: gzip, deflate
If lighttpd sees this header in the request, it can compress the response using one of the methods listed by the client. The web server notifies the web client of this via the Content-Encoding header in the response:
Content-Encoding: gzip
This is used to negotiate the most suitable compression method. Lighttpd support deflate, gzip and bzip2.
Configure mod_compress
Open your lighttpd.conf file:# vi /etc/lighttpd/lighttpd.conf
Append mod_compress to server.modules directive:
server.modules += ( "mod_compress" )
Setup compress.cache-dir to stored all cached file:
compress.cache-dir = "/tmp/lighttpdcompress/"
Finally, define mimetypes to get compressed. Following will allow to compress javascript, plain text files, css file,xml file etc:
compress.filetype = ("text/plain","text/css", "text/xml", "text/javascript" )
Save and close the file. Create /tmp/lighttpdcompress/ file:
# mkdir -p /tmp/lighttpdcompress/
# chown lighttpd:lighttpd /tmp/lighttpdcompress/
Restart lighttpd:
# /etc/init.d/lighttpd restart
How Do I Enable mod_compress Per Virtual Host?
Use conditional $HTTP host directive, for example turn on compression for theos.in:$HTTP["host"] =~ "theos\.in" { compress.cache-dir = "/var/www/cache/theos.in/" }
PHP Dynamic Compression
Open php.in file:# vi /etc/php.ini
To compress dynamic content with PHP please enable following two directives:
zlib.output_compression = On zlib.output_handler = On
Save and close the file. Restart lighttpd:
# service lighttpd restart
Cleaning Cache Directory
You need to run a shell script for cleaning out cache directory.Tags: Browsing, Download, Gzip, Improve, Lighttpd, mod_compress, Speed
Spin Up A VPS Server In No Time Flat
Simple Setup
Full Root Access
Straightforward Pricing
DEPLOY A SECURE VPS SERVER TODAY!Leave a Reply
Feedbacks
![]() This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. |