PHP程序员站--PHP编程开发平台
 当前位置:主页 >> 服务器 >> 其他服务器 >> 

mod_compress: Lighttpd Gzip Compression To Improve Download and Browsing Speed

mod_compress: Lighttpd Gzip Compression To Improve Download and Browsing Speed

来源:phperz.com  作者:phperz.com  发布时间:2011-12-25
翻译的老外的文章,本人的E文也是极烂,所以以下只做大概注释。 Gzip 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 t

翻译的老外的文章,本人的E文也是极烂,所以以下只做大概注释。
Gzip 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.
这一长串说的大概是Gzip是个很流行的压缩模块,目前大多数的浏览器都支持压缩的数据传输等一些废话。

mod_compress for Lighttpd 1.4.xx
lighttpd 1.4.xx的mod_compress模块介绍
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:
lighttpd 1.4使用mod_compress模块来支持gzip压缩。这个模块可以减少网页加载时间和加强服务器的吞吐量。大多数的浏览器都支持页面压缩,Accept-Encoding的header头:

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:
如下你看到你请求的网页响应头有以下标示,则说明当前请求的页面是通过gzip压缩过的。(额,这个和上在那个都可以用firebug看)
Content-Encoding: gzip

This is used to negotiate the most suitable compression method. Lighttpd support deflate, gzip and bzip2.
Lighttpd支持gzip和bzip2二种格式的压缩方式
Configure mod_compress
配置lighttpd的mod_compress模块
Open your lighttpd.conf file:
打开lighttpd.conf配置文件
# vi /etc/lighttpd/lighttpd.conf

Append mod_compress to server.modules directive:
添加lighttpd的mod_compress指令
server.modules += ( "mod_compress" )

Setup compress.cache-dir to stored all cached file:
配置压缩文件的cache目录
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:
定义需要压缩的文件类型一般压缩html,js,css就行了,
compress.filetype           = ("text/plain","text/css", "text/xml", "text/javascript" )

Save and close the file.

Create /tmp/lighttpdcompress/ file:
创建刚才定义的cache目录
# mkdir -p /tmp/lighttpdcompress/
# chown lighttpd:lighttpd /tmp/lighttpdcompress/

注:这个目录lighttpd账户要有写权限
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:
为每个虚拟主机指向cache目录,例:
$HTTP["host"] =~ "theos\.in" {
  compress.cache-dir = "/var/www/cache/theos.in/"
}

PHP dynamic compression
配置php的压缩模块
Open php.ini file:
打开php.ini配置文件
# vi /etc/php.ini

To compress dynamic content with PHP please enable following two directives:
要打开php的压缩需要激活以下二个指令
zlib.output_compression = On
zlib.output_handler = On

Save and close the file.

Restart lighttpd:
重启服务器
# service lighttpd restart

Cleaning cache directory
清除cache目录
You need to run a shell script for cleaning out cache directory.
注:你必须的搞一个shell教本,定期的清理cache目录(压缩后的文件临时目录,就是你上面配置的compress.cache-dir指定的目录)
附:关于compress.filetype的类型标示请参考本站另一篇文章:lighttpd开启gzip压缩

译:老鼠


延伸阅读:
告诉你如何关闭GZIP,多种程序方法
文件压缩成Gzip格式的类
使用mod_gzip加速你的html页面
PHP使用zlib扩展实现页面GZIP压缩输出
php对gzip文件或者字符串解压实例参考
使用PHP和GZip压缩网站JS/CSS文件加速网站访问速度
php启用gzip页面压缩示例
Linux空间用Gzip对网页内容进行压缩
什么是GZIP
IIS或Apache启用GZIP压缩优化网站
apache性能优化之启用gzip压缩
lighttpd开启gzip压缩
Lighttpd1.4.20服务端启用GZIP压缩
Tags: mod_compress   lighttpd   gzip  
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号