下载相关软件
cd /usr/local/src/
wget http://www.lighttpd.net/download/lighttpd-1.4.15.tar.gz
tar zxvf lighttpd-1.4.15.tar.gz
cd lighttpd-1.4.15
-
编译安装
./configure --prefix=/usr/local/lighttpd-1.4.15 \ --with-bzip2 \ --with-memcache make make install -
创建目录与配置文件
ln -s /usr/local/lighttpd-1.4.15/ /usr/local/lighttpd - mkdir -p /www/pages mkdir /www/logs mkdir /usr/local/lighttpd/htdocs mkdir /usr/local/lighttpd/logs mkdir /usr/local/lighttpd/etc cp ./doc/lighttpd.conf /usr/local/lighttpd/etc/ cd /usr/local/lighttpd/
-
配置lighttpd.conf
vi etc/lighttpd.conf找到 server.modules
删除 mod_fastcgi 前的注释
跟据你的需求修改下面定义
server.document-root = "/usr/local/lighttpd/htdocs/"
server.errorlog = "/usr/local/lighttpd/logs/lighttpd.error.log"
accesslog.filename = "/usr/local/lighttpd/logs/access.log"
注释 $HTTP["url"]
#$HTTP["url"] =~ "\.pdf$" { # server.range-requests = "disable" #} -
运行lighttpd
/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf测试
curl http://ip/ 因为/www/pages/下没有HTML页面所以返回:
404 - Not Found
1.3.1. shell script
lighttpd script
例 3.1. /etc/init.d/lighttpd
--------------------------------------------------------------------------------------------------------------
#!/bin/bash
# lighttpd init file for web server
#
# chkconfig: - 100 100
# de script ion: Security, speed, compliance, and flexibility--all of these describe LightTPD which is rapidly redefining efficiency of a webserver;
# as it is designed and optimized for high performance environments.
# author: Neo Chen<openunix@163.com>
#
# processname: $PROG
# config:
# pidfile: /var/run/lighttpd
# source function library
. /etc/init.d/functions
PREFIX=/usr/local/lighttpd
PROG=$PREFIX/sbin/lighttpd
OPTIONS="-f /usr/local/lighttpd/etc/lighttpd.conf"
USER=daemon
RETVAL=0
prog="lighttpd"
start() {
echo -n $"Starting $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
daemon --user=$USER $PROG $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lighttpd
fi;
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
killproc $PROG
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/lighttpd
fi;
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc $PROG -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
condrestart(){
[ -e /var/lock/subsys/lighttpd ] && restart
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
status lighttpd
RETVAL=$?
;;
*)
echo $"Usage: $0 "
RETVAL=1
esac
exit $RETVAL
--------------------------------------------------------------------------------------------------------------
2. /etc/lighttpd/lighttpd.conf
2.1. max-worker / max-fds
max-worker 我一般设置为与处理器数目相同。
max-fds 最大连接数
server.max-worker = 24 server.max-fds = 4096
2.2. accesslog.filename
通过cronolog切割日志
#### accesslog module #accesslog.filename = "/www/logs/lighttpd.access.log" accesslog.filename = "| /usr/local/sbin/cronolog /www/logs/%Y/%m/%d/access.log"
2.3. ETags
disable etags
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) static-file.etags = "disable"
2.4. server.tag
隐藏服务器信息
server.tag = "Apache"
测试结果Server: Apache
curl -I http://172.16.0.7/ HTTP/1.1 200 OK Content-Type: text/html Content-Length: 4692 Date: Fri, 04 Nov 2011 12:33:19 GMT Server: Apache
转载于:https://blog.51cto.com/jinyan2049/878720