当前位置: 首页 > Web与应用 > 正文

#lighttpd默认只启动一个进程工作,但也支持apache那样启动多个进程

server.max-worker = 4

# max-connections == max-fds/2 (maybe /3)
server.max-connections = 1024
server.max-fds = 2048

#Maximum number of seconds until an idling keep-alive connection is dropped.
server.max-keep-alive-idle = 5
server.max-keep-alive-requests = 1000

#stat() system call caching.
#lighttpd can utilize FAM/Gamin to cache stat call.
#possible values are: disable, simple or fam.
#disable
#simple (default) cache each stat() call for one second.
#fam if FAM or gamin are installed and lighty is linked against those libraries you can use them to control the freshness of the stat-cache.

server.stat-cache-engine = “simple”

#Module: mod_alias
alias.url = ( “/cgi-bin/” => “/var/www/servers/www.example.org/cgi-bin/” )

#You can add additional aliases by:
alias.url += ( “/content” => “/var/www/servers/www.somecontent.org/” )

#compress
#override default set of allowed encodings
compress.allowed-encodings = (”bzip2″, “gzip”, “deflate”)

#compress.cache-dir
compress.cache-dir = “/var/www/cache/”

#compress.filetype
#mimetypes which might get compressed
#Keep in mind that compressed JavaScript and CSS files are broken in some browsers. Not setting any filetypes will result in no files being compressed.
#Default: not set
compress.filetype = (”text/plain”, “text/html”)

#Display compressed files

$HTTP["url"] =~ “\.diff\.gz” {
setenv.add-response-header = ( “Content-Encoding” => “gzip” )
mimetype.assign = ()
}

#Compressing Dynamic Content
zlib.output_compression = On
zlib.output_handler = 1

PHP
To compress dynamic content with PHP please enable ::

zlib.output_compression = On
zlib.output_handler = 1

in the php.ini as PHP provides compression support by itself.

mod_compress of lighttpd 1.5 r1992 may not set correct Content-Encoding with php-fcgi.
A solution to that problem would be:

1.disable mod_compress when request a php file::

$HTTP["url"] !~ “\.php$” {
compress.filetype = (”text/plain”, “text/html”, “image/gif”, “text/javascript”, “text/css”, “text/xml”)
}

2.enable mod_setenv of your lighttpd::
server.modules += ( “mod_setenv” )

3.manually set Content-Encoding::
$HTTP["url"] =~ “\.php$” {
setenv.add-response-header = ( “Content-Encoding” => “gzip”)
}

# evasive.max-conns-per-ip : mod_evasive is a very simplistic module to limit connections per IP.

evasive.max-conns-per-ip = 1

$HTTP["host"] == “example.com” {
evasive.max-conns-per-ip = 2
}
$HTTP["host"] == “example2.com” {
evasive.max-conns-per-ip = 0
}

expire.url

expire.url = ( “/images/” => “access 1 hours” )

or
$HTTP["url"] =~ “^/images/” {
expire.url = ( “” => “access 1 hours” )
}

Module: mod_mem_cache
需要mod_mem_cache支持
-------------------------------
mem-cache.filetypes
content-type arrays which want to put into memory.

mem-cache.filetypes=(”text/css”)
Default: not set, cache all files

mem-cache.enable
enable or disable mod_mem_cache.

mem-cache.enable = “disable”
$HTTP["host"] == “images.example.org” {
mem-cache.enable = “enable”
}

Default: enable

mem-cache.max-memory
maxium memory in Mbytes mod-mem-cache can use.

Default: 512 (means 512 ”Megabytes”).

mem-cache.max-file-size
maxium file size in Kbytes of single file to cache in memory.

Default: 512 (means 512 ”Kilobytes”).

mem-cache.lru-remove-count
number of cached memory items to remove when used memory reached maxmemory by LRU algorthim

Default: 200.

mem-cache.expire-time
memory cache’s expire time in minutes.

mem-cache.expire-time = 1440 # 1 day

Default: 0 (means to check file update for every request)

mem-cache.slru-thresold
Adjusts slru threshold (against hit counter)

Default: 0 (disabled)
--------------------------------------

connection.kbytes-per-second,server.kbytes-per-second
还有值得一提的时lighttpd可以限制每个连接或则特定虚拟机的流量。

来自:http://hi.baidu.com/wanqiai/blog/item/1e09b651c427972d43a75b7a.html

[分享]Lighttpd 性能优化 (max-worker,compress,evasive,mod_mem_cache):目前有 3 条评论

发表评论