configuration.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. ==================
  2. Configuration File
  3. ==================
  4. ------------
  5. Module: core
  6. ------------
  7. :Author: Jan Kneschke
  8. :Date: $Date$
  9. :Revision: $Revision$
  10. :abstract:
  11. the layout of the configuration file
  12. .. meta::
  13. :keywords: lighttpd, configuration
  14. .. contents:: Table of Contents
  15. Description
  16. ===========
  17. Basic Syntax
  18. ------------
  19. A BNF like notation: ::
  20. option : NAME = VALUE
  21. merge : NAME += VALUE
  22. NAME : modulename.key
  23. VALUE : ( <string> | <integer> | <boolean> | <array> | VALUE [ + VALUE ]*)
  24. <string> : "text"
  25. <integer>: digit*
  26. <boolean>: ( "enable" | "disable" )
  27. <array> : "(" [ <string> "=>" ] <value> [, [ <string> "=>" ] <value> ]* ")"
  28. INCLUDE : "include" VALUE
  29. INCLUDE_SHELL : "include_shell" STRING_VALUE
  30. Example
  31. -------
  32. ::
  33. # default document-root
  34. server.document-root = "/var/www/example.org/pages/"
  35. # TCP port
  36. server.port = 80
  37. # selecting modules
  38. server.modules = ( "mod_access", "mod_rewrite" )
  39. # variables, computed when config is read.
  40. var.mymodule = "foo"
  41. server.modules += ( "mod_" + var.mymodule )
  42. # var.PID is initialised to the pid of lighttpd before config is parsed
  43. # include, relative to dirname of main config file
  44. include "mime.types.conf"
  45. # read configuration from output of a command
  46. include_shell "/usr/local/bin/confmimetype /etc/mime.types"
  47. Conditional Configuration
  48. =========================
  49. Most options can be configured conditionally by using the following syntax
  50. (including nesting).
  51. ::
  52. <field> <operator> <value> {
  53. ...
  54. <field> <operator> <value> {
  55. ... nesting: match only when parent match
  56. }
  57. }
  58. else <field> <operator> <value> {
  59. ... the "else if" block
  60. }
  61. where <field> is one of one of the following:
  62. $HTTP["cookie"]
  63. match on cookie
  64. $HTTP["scheme"]
  65. match on scheme
  66. $HTTP["host"]
  67. match on host
  68. $HTTP["useragent"]
  69. $HTTP["user-agent"]
  70. match on useragent
  71. $HTTP["referer"]
  72. match on referer
  73. $HTTP["method"]
  74. math on the http method
  75. $HTTP["url"]
  76. match on url
  77. $HTTP["query-string"]
  78. match on the (not decoded) query-string
  79. $HTTP["remoteip"]
  80. $HTTP["remote-ip"]
  81. match on the remote IP or a remote Network
  82. $HTTP["language"]
  83. match on the Accept-Language header
  84. $SERVER["socket"]
  85. match on socket. Value must be on the format "ip:port" where ip is an IP
  86. address and port a port number. Only equal match (==) is supported.
  87. It also binds the daemon to this socket. Use this if you want to do IP/port-
  88. based virtual hosts.
  89. <operator> is one of:
  90. ==
  91. string equal match
  92. !=
  93. string not equal match
  94. =~
  95. perl style regular expression match
  96. !~
  97. perl style regular expression not match
  98. and <value> is either a quoted ("") literal string or regular expression.
  99. Example
  100. -------
  101. ::
  102. # disable directory-listings for /download/*
  103. dir-listing.activate = "enable"
  104. $HTTP["url"] =~ "^/download/" {
  105. dir-listing.activate = "disable"
  106. }
  107. # handish virtual hosting
  108. # map all domains of a top-level-domain to a single document-root
  109. $HTTP["host"] =~ "(^|\.)example\.org$" {
  110. server.document-root = "/var/www/htdocs/example.org/pages/"
  111. }
  112. # multiple sockets
  113. $SERVER["socket"] == "127.0.0.1:81" {
  114. server.document-root = "..."
  115. }
  116. $SERVER["socket"] == "127.0.0.1:443" {
  117. ssl.pemfile = "/var/www/certs/localhost.pem"
  118. ssl.engine = "enable"
  119. server.document-root = "/var/www/htdocs/secure.example.org/pages/"
  120. }
  121. # deny access for all googlebot
  122. $HTTP["useragent"] =~ "Google" {
  123. url.access-deny = ( "" )
  124. }
  125. # deny access for all image stealers
  126. $HTTP["referer"] !~ "^($|http://www\.example\.org)" {
  127. url.access-deny = ( ".jpg", ".jpeg", ".png" )
  128. }
  129. # deny the access to www.example.org to all user which
  130. # are not in the 10.0.0.0/8 network
  131. $HTTP["host"] == "www.example.org" {
  132. $HTTP["remoteip"] != "10.0.0.0/8" {
  133. url.access-deny = ( "" )
  134. }
  135. }
  136. Using variables
  137. ===============
  138. You can set your own variables in the configuration to simplify your config.
  139. ::
  140. var.basedir = "/home/www/servers/"
  141. $HTTP["host"] == "www.example.org" {
  142. server.name = "www.example.org"
  143. include "incl-base.conf"
  144. }
  145. in incl-base.conf:
  146. server.document-root = basedir + server.name + "/pages/"
  147. accesslog.filename = basedir + server.name + "/logs/access.log"
  148. You can also use environment variables or the default variables var.PID and
  149. var.CWD: ::
  150. var.basedir = env.LIGHTTPDBASE
  151. $HTTP["host"] == "www.example.org" {
  152. server.name = "www.example.org"
  153. include "incl-base.conf"
  154. include "incl-fastcgi.conf"
  155. }
  156. in incl-fastcgi.conf:
  157. fastcgi.server = ( ... => ((
  158. "socket" => basedir + server.name + "/tmp/fastcgi-" + PID + ".sock"
  159. )) )
  160. Or like the lighttpd script for rails does:
  161. var.basedir = var.CWD
  162. server.document-root = basedir + "/public/"
  163. Global context
  164. ==============
  165. ::
  166. global {
  167. ...
  168. }
  169. You don't need it in the main configuration file. But you might have
  170. difficulty setting server wide configuration inside a included-file from
  171. conditionals.
  172. Example
  173. -------
  174. ::
  175. in lighttpd.conf:
  176. server.modules = ()
  177. $HTTP["host"] == "www.example.org" {
  178. include "incl-php.conf"
  179. }
  180. in incl-php.conf:
  181. global {
  182. server.modules += ("mod_fastcgi")
  183. static-file.exclude-extensions += (".php")
  184. }
  185. fastcgi.server = "..."
  186. Options
  187. =======
  188. server module
  189. -------------
  190. main sections
  191. `````````````
  192. server.document-root
  193. document-root of the webserver
  194. This variable has the specified as it will be used for all requests
  195. without a Host: header and for all with a know hostname which you
  196. might have specified with one of the above conditionals.
  197. Default: no default, required
  198. server.bind
  199. IP address, hostname or absolute path to the unix-domain socket the server
  200. listen on.
  201. Default: bind to all interfaces
  202. Example: ::
  203. server.bind = "127.0.0.1"
  204. server.bind = "www.example.org"
  205. server.bind = "/tmp/lighttpd.socket"
  206. server.port
  207. tcp-port to bind the server to
  208. .. note:: port belows 1024 require root-permissions
  209. Default: 80 (443 if ssl is enabled)
  210. server.use-ipv6
  211. bind to the IPv6 socket
  212. server.defer-accept
  213. set TCP_DEFER_ACCEPT to the specified value on the socket if the value is > 0
  214. and TCP_DEFER_ACCEPT is available on the platform (linux2.4+)
  215. Default: 0
  216. server.bsd-accept-filter
  217. set SO_ACCEPTFILTER on listen sockets (*BSD systems, e.g. FreeBSD)
  218. e.g. server.bsd-accept-filter = "httpready"
  219. or server.bsd-accept-filter = "dataready"
  220. Default: "" (none)
  221. server.tag
  222. set the string returned by the Server: response header
  223. Default: lighttpd <current-version>
  224. server.errorlog
  225. pathname of the error-log
  226. Default: either STDERR or ``server.errorlog-use-syslog``
  227. server.errorlog-use-syslog
  228. send errorlog to syslog
  229. Default: disabled
  230. server.chroot
  231. root-directory of the server
  232. NOTE: requires root-permissions
  233. server.username
  234. username used to run the server
  235. NOTE: requires root-permissions
  236. server.groupname
  237. groupname used to run the server
  238. NOTE: requires root-permissions
  239. server.follow-symlink
  240. allow to follow-symlinks
  241. Default: enabled
  242. index-file.names
  243. list of files to search for if a directory is requested
  244. e.g.: ::
  245. index-file.names = ( "index.php", "index.html",
  246. "index.htm", "default.htm" )
  247. if a name starts with slash this file will be used a index generator
  248. for all directories.
  249. server.modules
  250. modules to load
  251. .. note:: the order of the modules is important.
  252. The modules are executed in the order as they are specified. Loading
  253. mod_auth AFTER mod_fastcgi might disable authentication for fastcgi
  254. backends (if check-local is disabled).
  255. As auth should be done first, move it before all executing modules (like
  256. proxy, fastcgi, scgi and cgi).
  257. rewrites, redirects and access should be first, followed by auth and
  258. the docroot plugins.
  259. Afterwards the external handlers like fastcgi, cgi, scgi and proxy and
  260. at the bottom the post-processing plugins like mod_accesslog.
  261. e.g.: ::
  262. server.modules = ( "mod_rewrite",
  263. "mod_redirect",
  264. "mod_alias",
  265. "mod_access",
  266. "mod_auth",
  267. "mod_authn_file",
  268. "mod_status",
  269. "mod_simple_vhost",
  270. "mod_evhost",
  271. "mod_userdir",
  272. "mod_secdownload",
  273. "mod_fastcgi",
  274. "mod_proxy",
  275. "mod_cgi",
  276. "mod_ssi",
  277. "mod_deflate",
  278. "mod_usertrack",
  279. "mod_expire",
  280. "mod_rrdtool",
  281. "mod_accesslog" )
  282. Starting with lighttpd 1.4.0 three default modules are loaded automatically:
  283. - mod_indexfile
  284. - mod_dirlisting
  285. - mod_staticfile
  286. server.event-handler
  287. set the event handler
  288. Default: "poll"
  289. server.pid-file
  290. set the name of the .pid-file where the PID of the server should be placed.
  291. This option is used in combination with a start-script and the daemon mode
  292. Default: not set
  293. server.max-request-size
  294. maximum size in kbytes of the request (header + body). Only applies to POST
  295. requests.
  296. Default: 2097152 (2GB)
  297. server.max-worker
  298. number of worker processes to spawn. This is usually only needed on servers
  299. which are fairly loaded and the network handler calls delay often (e.g. new
  300. requests are not handled instantaneously).
  301. Default: 0
  302. server.name
  303. name of the server/virtual server
  304. Default: hostname
  305. server.max-keep-alive-requests
  306. maximum number of request within a keep-alive session before the server
  307. terminates the connection
  308. Default: 128
  309. server.max-keep-alive-idle
  310. maximum number of seconds until a idling keep-alive connection is dropped
  311. Default: 30
  312. server.max-read-idle
  313. maximum number of seconds until a waiting, non keep-alive read times out
  314. and closes the connection
  315. Default: 60
  316. server.max-write-idle
  317. maximum number of seconds until a waiting write call times out and closes
  318. the connection
  319. Default: 360
  320. server.error-handler-404
  321. uri to call if the requested file results in a 404
  322. Default: not set
  323. Example: ::
  324. server.error-handler-404 = "/error-404.php"
  325. server.protocol-http11
  326. defines if HTTP/1.1 is allowed or not.
  327. Default: enabled
  328. server.range-requests
  329. defines if range requests are allowed or not.
  330. Default: enabled
  331. SSL engine
  332. ``````````
  333. ssl.pemfile
  334. path to the PEM file for SSL support
  335. debugging
  336. `````````
  337. debug.dump-unknown-headers
  338. enables listing of internally unhandled HTTP-headers
  339. e.g. ::
  340. debug.dump-unknown-headers = "enable"
  341. mimetypes
  342. `````````
  343. mimetype.assign
  344. list of known mimetype mappings
  345. NOTE: if no mapping is given "application/octet-stream" is used
  346. e.g.: ::
  347. mimetype.assign = ( ".png" => "image/png",
  348. ".jpg" => "image/jpeg",
  349. ".jpeg" => "image/jpeg",
  350. ".html" => "text/html",
  351. ".txt" => "text/plain" )
  352. The list is compared top down and the first match is taken. This is
  353. important if you have matches like: ::
  354. ".tar.gz" => "application/x-tgz",
  355. ".gz" => "application/x-gzip",
  356. If you want to set another default mimetype use: ::
  357. ...,
  358. "" => "text/plain" )
  359. as the last entry in the list.
  360. mimetype.use-xattr
  361. If available, use the XFS-style extended attribute interface to
  362. retrieve the "Content-Type" attribute on each file, and use that as the
  363. mime type. If it's not defined or not available, fall back to the
  364. mimetype.assign assignment.
  365. e.g.: ::
  366. mimetype.use-xattr = "enable"
  367. on shell use:
  368. $ attr -s Content-Type -V image/svg svgfile.svg
  369. or
  370. $ attr -s Content-Type -V text/html indexfile
  371. debugging
  372. `````````
  373. debug.log-request-header
  374. default: disabled
  375. debug.log-response-header
  376. default: disabled
  377. debug.log-file-not-found
  378. default: disabled
  379. debug.log-request-handling
  380. default: disabled
  381. debug.log-ssl-noise
  382. default: disabled