`
hupy
  • 浏览: 186694 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

lighttpd+modcache实现对小图片的Cache

阅读更多

安装环境
操作系统: CentOS release 5.2 (Final)
Kernel: 2.6.18-92.el5PAE

软件列表
fam-latest.tar.gz
gamin-0.1.10.tar.gz
pcre-7.9.tar.gz
lighttpd-1.4.23.modcache.v.1.8.0.tar.gz

软件存放位置
/data/software

安装过程
#cd /data/software/pkg
安装依赖插件pcre, fam, gamin
关于FAM http://oss.sgi.com/projects/fam/faq.html
关于gamin http://www.gnome.org/~veillard/gamin/overview.html
See also: http://trac.lighttpd.net/trac/wiki/server.stat-cache-engineDetails
#tar zxvf ../pcre-7.9.tar.gz
#cd pcre-7.9
#./configure
#make && make install
#cd ..
#tar zxvf ../fam-latest.tar.gz
#cd fam-2.7.0/
#./configure
#make && make install
#cd ..
#tar zxvf ../gamin-0.1.10.tar.gz
#cd gamin-0.1.10
#./configure
#make && make install

安装lighttpd with modcache
#cd /data/software/pkg
#tar zxvf ../lighttpd-1.4.23.modcache.v.1.8.0.tar.gz
#cd lighttpd-1.4.23
#./configure --with-fam --prefix=/usr/local/lighttpd
#make && make install

编辑lighttpd配置文件
#cp doc/lighttpd.conf /etc/
#vi /etc/lighttpd.conf

#启用的modules
server.modules              = (
                                "mod_redirect",
                                "mod_access",
                                "mod_status",
                                "mod_cache",
                                "mod_proxy",
                                "mod_compress",
                                "mod_expire",
                                "mod_accesslog" )

server.pid-file            = "/var/run/lighttpd.pid"

server.max-keep-alive-requests = 16
server.max-keep-alive-idle = 4
server.max-read-idle = 60
server.max-write-idle = 360

#使用epoll作为事件处理
server.event-handler = "linux-sysepoll"

#使用sendfile
server.network-backend = "linux-sendfile"

#修改最大file descriptions,跟squid相同
server.max-fds = 65535

#启用fam作为stat处理方法
server.stat-cache-engine = "fam"

#此项打开以后缓存文件时将忽略?,即a.jpg?xxx和a.jpg?xyz都等同于a.jpg
cache.support-queries = "enable"

#指定本地缓存存放路径
cache.bases = ("/srv/lcache")

#定义刷新
cache.refresh-pattern = (
        "\.(?i)(flv)$" => "0 fetchall-for-range-request flv-streaming", # to work with mod_flv_streaming for flv files
        "\.(?i)(js|css|xml)$" => "10080", # update js/css/xml every 7 days and on refresh requests
        "\.(?i)(htm|html|shtml)$" => "10080", # update html/htm/shtml every 7 days and on refresh requests
        "\.(?i)(jpg|bmp|jpeg|gif|png)$" => "60", # update graphics files every 2 hours
        "\.(?i)(rar|zip|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb|flv)$" => "0 fetchall-for-range-request", # cache media file forever
        "." => "60 update-on-refresh" # default to update every hour and on refresh requests
)

#允许purge的ip
cache.purge-host = "^(192\.168\.)"

#保存缓存时忽略站点主机名(需要多个站点缓存不同文件的不要启用)
cache.ignore-hostname = "enable"

#后端服务器(源站)
proxy.server               = ( "/" =>
                               ( "localhost" =>
                                 (
                                   "host" => "192.168.1.15",
                                   "port" => 80
                                 )
                               )
                             )

#这项一定要启用
proxy.worked-with-mod-cache = "enable"

#设置指定IP允许查看服务器状态和缓存命中率
$HTTP["remoteip"] =~ "192\.168\.1\.*" {
  status.status-url          = "/server-status"
  status.stastics-url        = "/cache-status"
}

#防盗链
$HTTP["referer"] !~ "^($|http://.*\.(baidu\.com|google\.com|google\.cn))" {
    url.redirect = ( ".*" => "http://img1.test.com/a.jpg" )
}

启动lighttpd
#/usr/local/lighttpd/sbin/lighttpd -f /etc/lighttpd.conf

参考文档
http://redmine.lighttpd.net/projects/1/wiki/Docs:Performance
http://blog.fosketts.net/2009/06/29/tuning-lighttpd-linux/
http://trac.lighttpd.net/trac/wiki/server.stat-cache-engineDetails

关于日志rotate和启动脚本
http://www.cyberciti.biz/tips/lighttpd-rotating-logs-with-logrotate.html
http://www.cyberciti.biz/tips/redhat-enterprise-linux-lighttpd-fastcgi-php.html

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://iyubo.blogbus.com/logs/42429307.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics