您的位置:首页 > 理论基础 > 计算机网络

lighttpd + modcache (本人从来不觉得nginx有传说中那么夸张) 推荐

2010-01-06 10:55 363 查看
&FROST 20091007
各种webserver 各有千秋 本人从不觉得哪个最好 哪个不好!~  择优而用之但是自己的一点心得体会是 apache 作为资源前辈 却有其过人之处 对于 处理 静态 还是觉得 lighttpd 比 nginx 更胜一筹。当然 处理 php 动态程序 apache 稳定安全。 比 nginx 的 502 504 显得厚道多了简单介绍下 lighttpd 官方主页:www.lighttpd.net“引号”内文字属cp出品:“Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。”lighttpd 有个缺点就是单线程模式。。。lighttpd+modcache 类似于 nginx的proxy+cache 及传统squid 后起之秀 varish; 提供反向代理及CACHE服务http://redmine.lighttpd.net/wiki/1/Docs:ModCache“lighttpd是基于事件驱动的高性能web服务器。mod_cache是在lighttpd上运行的缓存插件。lighttpd+mod_cache 搭建的缓存系统,具有配置简单,性能高,在很多大型系统得到了广泛应用。”“mod_cache 是一个Lighttpd Web服务器的缓存模块,其功能类似Squid,只需要简单的配置。而且mod_cache 比Squid 的速度和运行效率都要高很多,这都是Lighttpd 的功劳。”1.编译安装
./configure --prefix=/usr/local/lighttpd --disable-ipv6 --with-pcre --with-zlib --with-bzip2 && make && make install

启动 lighttpd -D -f <configfile>

2.vim lighttpd.conf(一般应用)
选定需要的模块
server.modules = (
  )
server.username = "www"
server.groupname = "www"
server.document-root = "/usr/local/lighttpd/htdocs/"
server.errorlog = "/usr/local/lighttpd/logs/error.log"
accesslog.filename = "/usr/local/lighttpd/logs/access.log"  

允许软链接
server.follow-symlink

禁止访问以 "~" ".inc" 结尾的文件
url.access-deny = ( "~", ".inc")

限制每s单个IP连接数
Module:mod_evasive [i?veisiv]
  evasive.max-conns-per-ip = 1
  $HTTP["host"] == "example.com" {
  evasive.max-conns-per-ip = 2
  }
  $HTTP["host"] == "example2.com" {
  evasive.max-conns-per-ip = 0
  }

启用目录列表
dir-listing.activate = "enable"
$HTTP["url"] =~ "^/download/" {
  dir-listing.activate = "disable"
}

启用压缩
Module:mod_compress
compress.allowed-encodings = ("bzip2", "gzip", "deflate")
compress.cache-dir = "/usr/local/lighttpd/cachedata/" 
compress.filetype = ("text/plain","text/html","text/javascript", "text/css", "text/xml")
#清除10天未被访问的缓存
#find /var/www/cache -type f -mtime +10 | xargs -r rm
# 针对vhost指定压缩目录 even better with virt-hosting
  $HTTP["host"] == "docs.example.org" {
  compress.cache-dir = "/var/www/cache/docs.example.org/" 
  }
!!!
Module:mod_deflate ###需补丁### http://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_Deflate
设置过期期限
Module: mod_expire
expire.url = ( "/images/" => "access 1 hour" )

代理功能
Module:mod_proxy
# “1” 启用 debug
#Use 1 to enable some debug output,0 to disable it .
proxy.debug = [01] 

  $HTTP["host"] == "www.frost.cn" {
  proxy.balance = "hash" # “hash” “round-robin” “fair”
  proxy.server = ( "/" => ( ( "host" => "10.0.0.10" ),
  ( "host" => "10.0.0.17" ) ) )
  }

server.max-keep-alive-requests = 128
server.max-keep-alive-idle = 30
server.max-read-idle = 60
server.max-write-idle = 360

#server.event-handler = "linux-sysepoll"

server.max-fds = 2048

3.vim lighttpd.conf(proxy + modcache 反向代理) http://blog.quehy.com/page/2/ server.modules = (
# ...., other modules 
 "mod_cache", # make sure mod_cache loaded before mod_proxy
 "mod_proxy"
)
cache.support-queries = "enable" #ignore '?' in url
cache.bases = ("/data/cache") #write cached files in /data/cache directory
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)$" => "240", # update js/css/xml every 4 hours and on refresh requests
 "\.(?i)(htm|html|shtml)$" => "30", # update html/htm/shtml every 30 minutes and on refresh requests
 "\.(?i)(jpg|bmp|jpeg|gif|png)$" => "2880", # update graphics files every 2 days
 "\.(?i)(rar|zip|wmv|avi|mp3|ape|rm|mpeg|mpg|wma|asf|rmvb|flv)$" => "0 fetchall-for-range-request", # cache media file forever
 "." => "30 update-on-refresh" # default to update every 30 minutes and on refresh requests
)
#mod_proxy setting, config your backend servers here
proxy.server = ( "/" =>
  (
  ( "host" => "x.x.x.x", "port" => 80 ) # real backend http server ip and port
  )
)
#it's important to enable proxy.worked-with-mod-cache or mod_proxy will not cooperate with modcache
proxy.worked-with-mod-cache = "enable"

未完!~ 待续 

附件:http://down.51cto.com/data/2354893
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐