- 论坛徽章:
- 0
|
二、配置:
1、创建站点文件目录、日志目录以及配置文件目录。
mkdir -pv /home/lighttpd/conf /home/lighttpd/htdocs /home/lighttpd/logs
2、创建配置文件:
使用如下命令创建配置文件
touch /home/lighttpd/conf/lighttpd.conf
编辑配置文件如下
vi /home/lighttpd/conf/lighttpd.conf
配置文件内容
#### 加载以下模块,请尤其注意这里的模块之间的顺序,一定要严格按照以下顺序排列,如果需要加入其他模块,请测试
server.modules = (
"mod_expire",
"mod_staticfile",
"mod_compress",
"mod_access",
"mod_accesslog" ,
)
#### 定义站点根目录
server.document-root = "/home/lighttpd/htdocs/"
#### 定义错误输出日志
server.errorlog = "/home/lighttpd/logs/error.log"
#### 定义运行时的进程文件,便于脚本控制
server.pid-file = "/home/lighttpd/logs/lighttpd.pid"
#### 定义默认站点文件
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm" )
#### 定义mime类型
mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jar" => "application/x-java-archive",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
# default mime type
"" => "application/octet-stream",
)
#### 定义轮转日志
accesslog.filename = "| /home/lighttpd/cronolog/sbin/cronolog /home/lighttpd/logs/access_%Y%m%d.log"
# url.access-deny = ( "~", ".inc" )
#### expire头配置,对html目录,js目录,以及css目录分别设置1、2、3个小时的超时时间。(请根据实际情况合理配置)
$HTTP["url"] =~ "/testhtml/"{
expire.url = ("" => "access 1 hours")
}
$HTTP["url"] =~ "/testjs/"{
expire.url = ("" => "access 2 hours")
}
$HTTP["url"] =~ "/testcss/"{
expire.url = ("" => "access 3 hours")
}
#### static 模块配置,禁止Etag
# static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
# static-file.etags = "disable"
etag.use-inode = "disable"
#### compress 模块配置
# 定义压缩文件的存放目录
compress.cache-dir = "/home/lighttpd/compress"
# 定义压缩的mime类型,对css、html和js文件进行压缩
compress.filetype = ("text/html","text/css","text/javascript")
#端口设置为2080,避免和apache冲突
server.port = 2080
server.network-backend = "writev"
server.max-keep-alive-requests = 4
server.max-keep-alive-idle = 5
server.max-fds = 3072
server.event-handler = "linux-sysepoll"
3、启动服务器:
编辑lighttpctl脚本来进行服务的启动和停止的控制:
vi /home/lighttpd/sbin/lightctl
chmod 700 /home/lighttpd/sbin/lightctl
编辑lighttpctl脚本如下:
#!/bin/bash
ARGV="$@"
if [ $# != 1 ] ; then
echo "Usage: lighttpctl stop|start"
exit
fi
cmd=$ARGV
exefile="/home/lighttpd/sbin/lighttpd"
echo $cmd
case $cmd in
stop)
if [ ! -f /home/lighttpd/logs/lighttpd.pid ] ; then
echo "The service is not running."
exit
fi
kill -9 `cat /home/lighttpd/logs/lighttpd.pid`
rm -rf /home/lighttpd/logs/lighttpd.pid
ERROR=$?
;;
start)
`$exefile -f /home/lighttpd/conf/lighttpd.conf`
ERROR=$?
;;
*)
echo "Usage: lightctl stop|start"
ERROR=$?
esac
exit $ERROR
/home/lighthttpd/sbin/lightctl start/stop启动停止服务
[ 本帖最后由 mars531706 于 2008-11-5 10:31 编辑 ] |
|