一、安装
1. 安装lighttpd
apt-get install lighttpd lighttpd-doc
重要的文件默认位置
配置文件
/etc/lighttpd/conf-available
/etc/lighttpd/conf-enabled
/etc/lighttpd/lighttpd.conf
日志文件
/var/log/lighttpd/access.log (需要lighttpd-enable-mod accesslog)
上传文件
/var/cache/lighttpd
命令工具
lighttpd
lighttpd-enable-mod lighttpd-disable-mod
lighttpd-angel
2.安装mysql
apt-get install mysql-server
3.安装php5-相关模块
使用apt-cache search php5查找php5相关模块,可以选择以下最常用的安装
apt-get install php5 php5-cli php5-cgi php5-dev php5-mysql php5-mcrypt php5-gd
二、模块启动(php5+fastcgi)
lighttpd-enable-mod fastcgilighttpd-enable-mod fastcgi-phplighttpd-enable-mod accessloglighttpd-enable-mod status
启动模块后,需要重启服务器
/etc/init.d/lighttpd force-reload
三、访问控制
服务器上的重要信息,例如服务器状态提取文件,需要给予适当的访问控制,例如只允许指定的IP访问
1. status的访问控制
$HTTP["remoteip"]=~ "xxx.xxx.xxx.xxx|xxx.xxx.xxx.xxx|xxx.xxx.xxx"{
status.status-url = "/server-status"
status.config-url = "/server-config"
status.statistics-url = "/server-statistics"
}
status.status-url = "/server-status"
status.config-url = "/server-config"
status.statistics-url = "/server-statistics"
}
2.url访问控制
$HTTP["remoteip"] !~ "xxx.xxx.xxx.xxx|xxx.xxx.xxx.xxx|xxx.xxx.xxx"{
$HTTP["url"] =~ "tz\.php"{
url.access-deny = ("")
}
}
$HTTP["url"] =~ "tz\.php"{
url.access-deny = ("")
}
}
四、日志格式设置
vim /etc/lighttpd/conf-available/10-accesslog.conf
日志样例如下accesslog.format = "%h %V %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
注意accesslog.format部分,具体意思如下211.138.23.98 www.tanjiti.com - [22/Oct/2013:04:05:47 -0700] "GET /s/jquery-migrate.min.js?ver=1 HTTP/1.1" 200 3068 "http://www.baidu.com" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0“
accesslog.format = "%h %V %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
%h name or address of remote-host --示例中的211.138.23.98
%V HTTP request host name --示例中的 www.tanjiti.com
%u authenticated user --示例中的-
%t timestamp of the end-time of the request --示例中的[22/Oct/2013:04:05:47 -0700]
%r request-line --示例中的GET /s/jquery-migrate.min.js?ver=1 HTTP/1.1
%s status-code --示例中的200
%b bytes sent for the body --示例中的3068
%{Referer}i HTTP Referer --示例中的http://www.baidu.com
%{User-Agent}i HTTP UserAgent --示例中的Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
五、 测试配置文件是否正确,启动lighttpd服务
lighttpd -t -f configfile
service lighttpd start