lighttpd配置实例
lighttpd异常自动重启脚本
1.建立脚本
vi /root/bin/check_lighttpd.sh
#!/bin/bash
date=`date +%Y-%m-%d-%H-%M`
if curl –head http://www.gaojinbo.com/index.html | grep "200" >/dev/null 2>&1 ; then
echo lighttpd is ok $date >>/root/bin/check_lighttpd.log
else
echo lighttpd is error $date >>/root/bin/check_lighttpd.log
/etc/init.d/lighttpd restart
fi
2.增加执行权限
chmod +x /root/bin/check_lighttpd.sh
3.添加到crontab
*/10 * * * * /root/bin/check_lighttpd.sh
===========================
lighttpd配置gzip压缩
编辑配置文件
vi /etc/lighttpd/lighttpd.conf
1.开启
"mod_compress",
2.添加类似配置
$HTTP["host"] =="www.gaojinbo.com" {
server.document-root ="/www/web/gaojinbo.com/www"
$HTTP["url"] =~ "^/static/" {
compress.cache-dir = "/www/tmp/lighttpd-compress/"
compress.filetype = ("text/plain", "text/html", "application/x-javascript", "text/css","application/javascript", "text/javascript")
}
}
=====================
cronolog分割lighttpd的日志
Cronolog是一款日志轮循(rotation)工具,可以用它来把Apache、Tomcat等Web服务器上输出的日志切分成按日或月保存的文件。
1.源码安装cronolog
cd /opt
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
tar zxvf ../cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make && make install
2.修改lighttpd配置文件使用cronolog进行日志rotate
#vi /etc/lighttpd.conf
server.errorlog = "|/usr/local/sbin/cronolog /var/log/lighttpd/error/%Y/%m/%d/error.log"
accesslog.filename = "|/usr/local/sbin/cronolog /var/log/lighttpd/access/%Y/%m/%d/access.log"
保存后重启lighttpd使配置生效。如果配置成功,系统进程里将会多出两个cronolog的进程,新的日志将保存在配置目录中按照年月日建立文件夹下
==================
lighttpd控制fastcgi进程数
lighttpd默认的fastcgi产生数是8
如果要增加或者减少fastcgi进程数
就需要修改配置文件,进行定制
( “localhost” =>
(
“socket” => “/var/run/lighttpd/php-fastcgi.socket”,
“bin-path” => “/usr/local/php/bin/php-cgi”,
“min-procs” => 1,
“max-procs” => 1,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “3”,
),
“bin-copy-environment” => (
“PATH”, “SHELL”, “USER”
),
“idle-timeout” => 20
)
)
)
就是PHP_FCGI_CHILDREN参数.控制fastcgi进程的产生数
有一点要注意
如果使用ea,xcache或者APC等等OPCODE加速器
一定要将max-procs设置为1
否则可能会产生问题.
========================
lighttpd限制IP访问指定URL
WEB服务器
lighttpd
1.编辑配置文件
vi /etc/lighttpd/lighttpd.conf
#example
$HTTP["host"] == "gaojinbo.com" {
status.status-url = "/server-status"
server.name = "gaojinbo.com"
server.document-root = "/www/www.gaojinbo.com"
$HTTP["remoteip"] !~ "119.107.106|129.145.100.138" {
$HTTP["url"] =~ "^/server-status" {
url.access-deny = ( "" )
}
}
}
2.重启服务
/etc/init.d/lighttpd restart
完成!
附:
Task: Match on the remote IP
For example block access to http://theos.in/stats/ url if IP address is NOT 192.168.1.5 and 192.168.1.10 (restrict access to these 2 IPs only):
Open /etc/lighttpd/lighttpd.conf file
# vi /etc/lighttpd/lighttpd.conf
Append following configuration directive:
$HTTP["remoteip"] !~ "200.19.1.5|210.45.2.7" {
$HTTP["url"] =~ "^/stats/" {
url.access-deny = ( "" )
}
}
Save and restart lighttpd:
# /etc/init.d/lighttpd restart
上一篇: 服务器集群技术比较