ighttpd学习笔记(安装配置,文件压缩,限制IP和限制速度,expire, rewirte)

ighttpd学习笔记(安装配置,文件压缩,限制IP和限制速度,expire, rewirte)


一. 基本安装

官方网站: http://www.lighttpd.net

./configure –prefix=/zhangjianfeng.com/app/lighttpd-1.4.19l

mkdir /zhangjianfeng.com/app/lighttpd-1.4.19/conf/

cp doc/lighttpd.conf /zhangjianfeng.com/app/lighttpd-1.4.19/conf/


手工启动方法: /zhangjianfeng.com/app/lighttpd-1.4.19/sbin/lighttpd -f /zhangjianfeng.com/app/lighttpd-1.4.19/conf/lighttpd.conf

服务控制脚本: 安装包自带了一个脚本, doc/rc.lighttpd, 简单修改一下就可以作服务控制脚本.

二.性能调整

server.max-fds = 8192

server.max-keep-alive-requests = 0

server.event-handler = "linux-sysepoll"

server.network-backend = "linux-sendfile"

#server.stat-cache-engine = "fam"

#server.max-worker = 2


三. 参数配置

server.username = "nobody"

server.groupname = "nobody"

server.error-handler-404 = "/error-404.php" #HTTP 404

server.document-root = "/var/www/example.org/pages/" # default document-root

server.port = 80 # TCP port

server.modules = ( "mod_access", "mod_rewrite" ) # selecting modules

include "mime.types.conf" # include, relative to dirname of main config file

server.follow-symlink

allow to follow-symlinks

index-file.names = ( "index.php", "index.html",

"index.htm", "default.htm" )

++ Conditional Configuration

# disable directory-listings for /download/*

dir-listing.activate = "enable"

$HTTP["url"] =~ "^/download/" {

dir-listing.activate = "disable"

}

# multiple sockets

$SERVER["socket"] == "127.0.0.1:81" {

server.document-root = "…"

}

# deny the access to www.example.org to all user which are not in the 10.0.0.0/8 network

$HTTP["host"] == "www.example.org" {

$HTTP["remoteip"] != "10.0.0.0/8" {

url.access-deny = ( "" )

}

}

# 静态文件压缩

compress.cache-dir = "/tmp/lighttpd/cache/compress"

compress.filetype = ("text/plain", "text/html","text/javascript","text/css")

compress.max-filesize = 128

# mod_expire扩展

expire.url = ( "/images/" => "access 21 hours" )

# rewirte & redirect

url.redirect = ( "^/st$" => "http://blog.zhangjianfeng.com/server-status" )

url.rewrite = ( "^/s$" => "/server-status" )

#mod_rewrite扩展,需要安装pcre

#redirect是客户端重定向,可以重定向到另外一个网站,redirect时目的地址可以是完整的uri

#rewrite是服务器端重定向,不能重定向到另外一个网站,浏览器不用重新发出请求,所以rewrite 时不能目的地址中含有域名

#配置虚拟主机

include "vhosts.conf"

$HTTP["host"] == "d1.zhangjianfeng.com" {

server.document-root = "/zhangjianfeng/data/www/d1/"

server.errorlog = "/zhangjianfeng/logs/lighttpd/d1/error.log"

accesslog.filename = "|/zhangjianfeng/app/cronolog-1.7.0/sbin/cronolog /zhangjianfeng/logs/lighttpd/d1/%Y/%m/%d.log"

}

++lighttpd限制IP和限制速度

#开启模块 "mod_evasive" #./lib/目录下应该有mod_evasive.so,1.4.9以后版本提供

server.modules = (

……

"mod_evasive"

……

);

#限制单IP最大数

evasive.max-conns-per-ip = 10

#限制流量

connection.kbytes-per-second = 128 #设0表示无限制

#也可以直接写到虚拟主机里面

$HTTP["host"] == "blog.zhangjianfeng.com" {

$HTTP["url"] =~ "\.(mp4|flv)$" {

#evasive.max-conns-per-ip = 10

connection.kbytes-per-second = 256

}

}

你可能感兴趣的:(linux,PHP,脚本,lighttpd,Access)