lighttpd配置gzip和cache

三月 1, 2010 by · Leave a Comment 

配置gzip主要是使用compress模块

  1. 激活compress模块,将lightppd.conf文件的mod_compress的注释去掉
  2. 配置压缩文件存放目录compress.cache-dir,注意运行lighttpd的用户需要有这个目录的读写权限,压缩文件的类型compress.filetype
  3. 将动态生成的php也gzip,修改php.ini,加上zlib.output_compression = On和zlib.output_handler = On
  4. 重启lighttpd

配置cache主要是使用expire模块

  1. 激活expire模块,将lightppd.conf文件的mod_expire的注释去掉
  2. 配置需要设置过期时间的host
  3. 重启lighttpd

最后配置如下:

1 $HTTP["host"] =~ "blog\.xiaocaihua\.com$" {
2  
3 #其他配置...
4 compress.cache-dir  =  "/home/flymouse//compress/"
5 compress.filetype  =  ("text/plain", "text/html", "application/x-javascript", "text/css", "application/javascript", "text/javascript")
6 $HTTP["url"] =~ "(\.png|\.css|\.js|\.jpg|\.gif)$" {
7 expire.url = ( "" => "access 2 months" ) # 配置静态文件缓存2个月
8 }
9 }

最后的Response header应该如下图,有Content-Encoding和Expires,max-age头。

http response header info

http响应的头信息

参考

  1. mod_compress 文档
  2. mod_expire 文档

转载自:小菜花

About admin

注意:

1、本站启用了审核机制,你的留言可能稍后才会显示,请不要重复提交,谢谢。
2、留言时的头像是Gravatar提供的服务。想设置的看这里
3、评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha