原贴:http://networld.tianyablog.com/blogger/post_show.asp?BlogID=40003&PostID=9144525&idWriter=0&Key=0
Lighttpd(4) 功能特性
# 配置超期
expire.url = ( "/www/" => "access 2 hours")
expire.url = ( "/www/mp3/" => "access 2 hours")
#
# 压缩
compress.cache-dir = "/var/www/cache/"
# 或者针对虚拟站点指定临时目录
$HTTP["host"] == "docs.example.org" {
compress.cache-dir = "/var/www/cache/docs.example.org/"
}
压缩文件类型
compress.filetype = ("text/plain", "text/html")
# 重定向
# 重定向到指定网址
url.redirect = ("^/" => "http://www.tianya.cn/index.asp")
# 变量传递
url.redirect = ("^/([0-9]+)$" => "http://cache.tianya.cn/publicforum/Content/house/1/$1.shtml")
url.redirect = ( "^/show/([0-9]+)/([0-9]+)$" => "http://www.example.org/show.php?isdn=$1&page$2")
# 面向虚拟主机的重定向
$HTTP["host"] =~ "^www/.(.*)" {
url.redirect = ( "^/(.*)" => "http://%1/$1" )
}
# 重写
# 代理
使用proxy-module模块。
# 两个选项:
1)proxy.debug
2)proxy.balance:hash(同一请求发送到同一主机)、round-robin(循环)、fair(缺省)
# 范例,
$HTTP["host"] == "www.example.org" {
proxy.balance = "hash"
proxy.server = ( "" => ( ( "host" => "10.0.0.10" ),
( "host" => "10.0.0.11" ),
( "host" => "10.0.0.12" ),
( "host" => "10.0.0.13" ),
( "host" => "10.0.0.14" ),
( "host" => "10.0.0.15" ),
( "host" => "10.0.0.16" ),
( "host" => "10.0.0.17" ) ) )
}
当一主机down机时,该机的请求被平等移动到其它服务器。使用Microsoft CARP算法。
# 流量修整
1)每个连接每秒流量限制(k)
connection.kbytes-per-second = 0
2)服务每秒流量限制
server.kbytes-per-second
# 在虚拟主机中限制
$HTTP["host"] == "www.example.org" {
server.kbytes-per-second = 128
}
# 目录列表
# 激活
dir-listing.activate = "enable"
# 控制在物理目录中
$HTTP["url"] =~ "^/download($|/)" {
dir-listing.activate = "enable"
}
dir-listing.hide-dotfiles = "enable" # 不显示隐藏文件
dir-listing.external-css = "" # 目录css风格显示的css文件路径
dir-listing.exclude = "" # 正则表达式,排队不显示的文件
dir-listing.encoding = "utf-8"
# 禁止googelbot机器人访问
$HTTP["useragent"] =~ "Google" {
url.access-deny = ( "" )
}
# 禁止所有图像盗链 (anti-hotlinking for images)
$HTTP["referer"] !~ "^($|http://www/.example/.org)" {
url.access-deny = ( ".jpg", ".jpeg", ".png" )
}
# 禁止非10.0.0.0/8的IP访问www.example.org
$HTTP["host"] == "www.example.org" {
$HTTP["remoteip"] != "10.0.0.0/8" {
url.access-deny = ( "" )
}
}
# 允许200.19.1.5和210.45.2.7访问www.example.org/admin/
$HTTP["host"] == "www.example.org" {
#!~ is a perl style regular expression not match
$HTTP["remoteip"] !~ "200.19.1.5|210.45.2.7" {
$HTTP["url"] =~ "^/admin/" {
url.access-deny = ( "" )
}
}
}
# 配置虚拟主机
启动模块mod_simple_vhost
$HTTP["host"] == "cache.tianya.cn" {
server.document-root = "/www/"
index-file.names = ( "index.shtml", "index.html",
"index.htm", "default.htm" )
}
$HTTP["host"] == "sample.tianya.cn" {
server.document-root = "/www/sample/"
index-file.names = ( "index.shtml", "index.html",
"index.htm", "default.htm" )
}
Lighttpd(4) 功能特性
# 配置超期
expire.url = ( "/www/" => "access 2 hours")
expire.url = ( "/www/mp3/" => "access 2 hours")
#
# 压缩
compress.cache-dir = "/var/www/cache/"
# 或者针对虚拟站点指定临时目录
$HTTP["host"] == "docs.example.org" {
compress.cache-dir = "/var/www/cache/docs.example.org/"
}
压缩文件类型
compress.filetype = ("text/plain", "text/html")
# 重定向
# 重定向到指定网址
url.redirect = ("^/" => "http://www.tianya.cn/index.asp")
# 变量传递
url.redirect = ("^/([0-9]+)$" => "http://cache.tianya.cn/publicforum/Content/house/1/$1.shtml")
url.redirect = ( "^/show/([0-9]+)/([0-9]+)$" => "http://www.example.org/show.php?isdn=$1&page$2")
# 面向虚拟主机的重定向
$HTTP["host"] =~ "^www/.(.*)" {
url.redirect = ( "^/(.*)" => "http://%1/$1" )
}
# 重写
# 代理
使用proxy-module模块。
# 两个选项:
1)proxy.debug
2)proxy.balance:hash(同一请求发送到同一主机)、round-robin(循环)、fair(缺省)
# 范例,
$HTTP["host"] == "www.example.org" {
proxy.balance = "hash"
proxy.server = ( "" => ( ( "host" => "10.0.0.10" ),
( "host" => "10.0.0.11" ),
( "host" => "10.0.0.12" ),
( "host" => "10.0.0.13" ),
( "host" => "10.0.0.14" ),
( "host" => "10.0.0.15" ),
( "host" => "10.0.0.16" ),
( "host" => "10.0.0.17" ) ) )
}
当一主机down机时,该机的请求被平等移动到其它服务器。使用Microsoft CARP算法。
# 流量修整
1)每个连接每秒流量限制(k)
connection.kbytes-per-second = 0
2)服务每秒流量限制
server.kbytes-per-second
# 在虚拟主机中限制
$HTTP["host"] == "www.example.org" {
server.kbytes-per-second = 128
}
# 目录列表
# 激活
dir-listing.activate = "enable"
# 控制在物理目录中
$HTTP["url"] =~ "^/download($|/)" {
dir-listing.activate = "enable"
}
dir-listing.hide-dotfiles = "enable" # 不显示隐藏文件
dir-listing.external-css = "" # 目录css风格显示的css文件路径
dir-listing.exclude = "" # 正则表达式,排队不显示的文件
dir-listing.encoding = "utf-8"
# 禁止googelbot机器人访问
$HTTP["useragent"] =~ "Google" {
url.access-deny = ( "" )
}
# 禁止所有图像盗链 (anti-hotlinking for images)
$HTTP["referer"] !~ "^($|http://www/.example/.org)" {
url.access-deny = ( ".jpg", ".jpeg", ".png" )
}
# 禁止非10.0.0.0/8的IP访问www.example.org
$HTTP["host"] == "www.example.org" {
$HTTP["remoteip"] != "10.0.0.0/8" {
url.access-deny = ( "" )
}
}
# 允许200.19.1.5和210.45.2.7访问www.example.org/admin/
$HTTP["host"] == "www.example.org" {
#!~ is a perl style regular expression not match
$HTTP["remoteip"] !~ "200.19.1.5|210.45.2.7" {
$HTTP["url"] =~ "^/admin/" {
url.access-deny = ( "" )
}
}
}
# 配置虚拟主机
启动模块mod_simple_vhost
$HTTP["host"] == "cache.tianya.cn" {
server.document-root = "/www/"
index-file.names = ( "index.shtml", "index.html",
"index.htm", "default.htm" )
}
$HTTP["host"] == "sample.tianya.cn" {
server.document-root = "/www/sample/"
index-file.names = ( "index.shtml", "index.html",
"index.htm", "default.htm" )
}