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

lighttpd开启gzip压缩

lighttpd开启gzip压缩

来源:phperz.com  作者:phperz.com  发布时间:2011-12-25
配置gzip主要是使用lightppd的compress模块 1,激活compress模块,将lightppd.conf文件的mod_compress的注释去掉 2,配置压缩文件存放目录compress.cache-dir,注意运行lighttpd的用户需要有这个目录的读写权限,压缩文件的类型compress.filetype 3,配置需要压缩的文件类

配置gzip主要是使用lightppd的compress模块
  1,激活compress模块,将lightppd.conf文件的mod_compress的注释去掉
  2,配置压缩文件存放目录compress.cache-dir,注意运行lighttpd的用户需要有这个目录的读写权限,压缩文件的类型compress.filetype
    3,配置需要压缩的文件类型compress.filetype, 一般情况下压缩html,css,js
    查找
    #### compress module
    #compress.cache-dir         = "/tmp/lighttpd/cache/compress/"
    #compress.filetype          = ("text/plain", "text/html")
    把compress.cache-dir和compress.filetype前面的#号去掉
    compress.filetype的文件类型见文章下面的附

将动态生成的php也gzip,修改php.ini,加上zlib.output_compression = On 和 zlib.output_handler = On
重启lighttpd: /etc/init.d/lighttpd restart
  

配置cache主要是使用expire模块
  激活expire模块,将lightppd.conf文件的mod_expire的注释去掉
  配置需要设置过期时间的host
  重启lighttpd

lighttpd.conf配置代码:

$HTTP["host"] =~ "www\.XXXXXX\.com$" {

#其他配置...
compress.cache-dir  =  "/home/YOUNAME/lighttpd/compress/"
compress.filetype  =  ("text/plain", "text/html", "application/x-javascript", "text/css", "application/javascript", "text/javascript")
$HTTP["url"] =~ "(\.png|\.css|\.js|\.jpg|\.gif)$" {
expire.url = ( "" => "access 2 months" ) # 配置静态文件缓存2个月
}
}

注意:mod_compress在mod_expire之前

附:compress.filetype的类型
 ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",


  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",


  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",


  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar"

 


延伸阅读:
告诉你如何关闭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 再爆漏洞 影响所有版本
lighttpd 1.4.30发布
Tags: lighttpd   gzip   压缩  
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号