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