安裝
apt-get install lighttpd
- lighttpd
- spawn-fcgi
查看
lighttpd -v
lighttpd/1.4.28 (ssl) - a light and fast webserver Build-Date: Dec 20 2011 22:59:43
lighttpd-disable-mod
lighttpd-enable-mod
設定
lighttpd/ |-- conf-available | |-- 05-auth.conf | |-- 10-accesslog.conf | |-- 10-cgi.conf | |-- 10-evasive.conf | |-- 10-evhost.conf | |-- 10-expire.conf | |-- 10-fastcgi.conf | |-- 10-flv-streaming.conf | |-- 10-no-www.conf | |-- 10-proxy.conf | |-- 10-rrdtool.conf | |-- 10-simple-vhost.conf | |-- 10-ssi.conf | |-- 10-ssl.conf | |-- 10-status.conf | |-- 10-userdir.conf | |-- 10-usertrack.conf | |-- 15-fastcgi-php.conf | |-- 90-debian-doc.conf | `-- README |-- conf-enabled `-- lighttpd.conf 2 directories, 21 files
比較特別的設定:
merge:
NAME += VALUE
INCLUDE_SHELL:
include_shell "STRING_VALUE.pl"
array:
( [ <string> "=>" ] <value> [, [ <string> "=>" ] <value> ]* )
Conditional Configuration
<field> <operator> <value> { ... } else <field> <operator> <value> { ... the "else if" block }
field:
- $???["???"]
operator 除 ==, != 外, 它有還有
- =~ perl style regular expression match
- !~ perl style regular expression not match
include file 內的 Global context:
global { ... }
User Variables
設定:
var.basedir = "/home/www/servers/"
使用:
server.document-root = basedir + server.name + "/pages/"
測試與啟動
lighttpd -t -f lighttpd.conf
Syntax OK
lighttpd -D -f lighttpd.conf
2012-10-28 16:53:46: (log.c.118) opening errorlog '/var/log/lighttpd/error.log' failed: Permission denied
- -f <name> filename of the config-file
- -t test the config-file, and exit
- -D don't go to background
/etc/init.d/lighttpd start
server.username = "www-data" server.groupname = "www-data"
mimetype.assign = ( ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png" )
virtual server
$HTTP["host"] == "www2.example.org" { server.document-root = "/var/www/servers/www2.example.org/pages/" }
index
index-file.names = ( "index.htm", "index.html" )
autoindex(mod_dirlisting)
全域:
dir-listing.encoding = "utf-8" server.dir-listing = "disable"
個別目錄:
$HTTP["url"] =~ "^/download($|/)" {
dir-listing.activate = "enable"
dir-listing.hide-dotfiles = "enable" <-- Defalut "disable"
dir-listing.encoding = "utf-8"
dir-listing.exclude = ( ".py$" ) <-- 不用加 * !!
dir-listing.set-footer = "Here is Root Directory" <-- Default "lighttpd/1.4.28"
}
modules
設定
server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", # "mod_rewrite", )
OR
server.modules += ( "mod_fastcgi" )
OR
include "conf.d/fastcgi.conf"
其他常用設定:
# which extensions should not be handle via static-file transfer
static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc", ".py" )
# deny access the file-extensions
url.access-deny = ( "~", ".inc", ".bak" )
mod_compress
compress.cache-dir = "/var/cache/lighttpd/compress/" compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
詳見:
- http://redmine.lighttpd.net/projects/lighttpd/wiki/Tutorials
- http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ConfigurationOpt...
- http://redmine.lighttpd.net/projects/lighttpd/repository/entry/trunk/doc...