Project

General

Profile

TutorialConfiguration » History » Revision 3

Revision 2 (jan, 2006-01-29 19:54) → Revision 3/28 (jan, 2006-01-29 20:34)

= == Configuration = 

 How much time do you have to setup lighttpd ? 5, 10 or more minutes ? 

 == 5 minutes == 

 You want to run a fast, low-resource server for static content ? 

 {{{ 
 server.document-root = "/var/www/servers/www.example.org/pages/" 

 server.port = 3000 

 mimetype.assign = ( 
   ".html" => "text/html",  
   ".txt" => "text/plain", 
   ".jpg" => "image/jpeg", 
   ".png" => "image/png" 
 ) 
 }}} 

 lighttpd will listen on port 3000/tcp and bind to all interfaces default. The few important mimetypes are assigned 
 and the document-root (the base direcorty that is used for all requests) is set. The files in the document-root have to be  
 readable by the user starting the webserver. 

 Now start the server for testing: 

 {{{ 
 $ lighttpd -f /etc/lighttpd/lighttpd.conf 
 }}} 

 and point your browser to  

 [http://127.0.0.1:3000/] 

 As you want to run the server in production quite soon you take the next seconds are on security: 

 {{{ 
 server.document-root = "/var/www/servers/www.example.org/pages/" 

 server.port = 80 

 server.username = "www" 
 server.groupname = "www" 

 mimetype.assign = ( 
   ".html" => "text/html",  
   ".txt" => "text/plain", 
   ".jpg" => "image/jpeg", 
   ".png" => "image/png" 
 ) 

 staticfile.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) 
 index-file.names = ( "index.html" ) 
 }}} 

 Now the webserver is listing on port 80, the default port for HTTP, and will switch to the user 'www' and the group 'www' as  
 the server has to be started as root to take control over port 80. 

 As last step we forbid the access to the source of some files which will be used later for generating dynamic content and rewrite 
 all requests to a directory to the 'index.html' configuration file in that directory. 

 == 10 minutes == 

 Conditionals, conditionals, conditionals: 

 The most important part in lighties configuration is the use of conditionals. They control via simple comparisions or regexes 
 if a default setting will be overwritten or not. 

 {{{ 
 server.document-root = "/var/www/servers/www.example.org/pages/" 

 server.port = 80 

 server.username = "www" 
 server.groupname = "www" 

 mimetype.assign = ( 
   ".html" => "text/html",  
   ".txt" => "text/plain", 
   ".jpg" => "image/jpeg", 
   ".png" => "image/png" 
 ) 

 staticfile.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) 
 index-file.names = ( "index.html" ) 

 $HTTP["host"] == "www2.example.org" { 
   server.document-root = "/var/www/servers/www2.example.org/pages/" 
 } 

 }}} 

 Now we have a new virtual server which will use the same settings as the first server, only the document-root 
 will be replaced by a new one. 

 This server shall have a download area which shall print a nice-looking dirlisting: 

 {{{ 
 server.document-root = "/var/www/servers/www.example.org/pages/" 

 server.port = 80 

 server.username = "www" 
 server.groupname = "www" 

 mimetype.assign = ( 
   ".html" => "text/html",  
   ".txt" => "text/plain", 
   ".jpg" => "image/jpeg", 
   ".png" => "image/png" 
 ) 

 staticfile.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) 
 index-file.names = ( "index.html" ) 

 $HTTP["host"] == "www2.example.org" { 
   server.document-root = "/var/www/servers/www2.example.org/pages/" 
   $HTTP["url"] =~ "^/download/" { 
     dir-listing.activate = "enable" 
   } 
 } 
 }}} 

 As you see conditonals can be nested: only found in the /download/ folder and its sub-folders have the {{{doc}}} directory listings 
 enabled. 

 With this basic steps you are ready to read on of the other chapters about: 

  tarball.   

 Read  

  * includes at http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes http://www.lighttpd.net/documentation/configuration.html 
  * php at http://www.lighttpd.net/documentation/fastcgi.html 

 == after 30 minutes == 

 Now you know the basic setup, includes and might have php or ruby already running. There is alot more to find out. use  

 http://trac.lighttpd.net/trac/file/branches/lighttpd-1.3.x/doc/lighttpd.conf 

 Most of it is described in examples in the default configuration file that you can find in the {{{doc/}}} directory  
 of the tarball or at http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/lighttpd.conf 

 The website also has the manual online: 

  * http://www.lighttpd.net/documentation/ 
  * the description of the config file structure http://www.lighttpd.net/documentation/configuration.html 

 as starting point for the configuration. 

 == Starting lighttpd as daemon == 

 You must specify the configuration file to lighttpd by running  

 {{{ 
 $ lighttpd -f /etc/lighttpd/lighttpd.conf 
 }}}