Project

General

Profile

TutorialConfiguration » History » Revision 13

Revision 12 (Anonymous, 2007-04-13 00:32) → Revision 13/28 (Anonymous, 2007-04-13 00:32)

h1. = Configuration 


 = 

 How much time do you have to set up lighttpd? 5 minutes? 10 minutes? more? 


 h2. 

 == 5 minutes 


 == 

 Want to run a fast, low-resource server for static content? It's easy: 


 <pre> 

 

 {{{ 
 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" 
 ) 
 </pre> 


 }}} 

 lighttpd will listen on TCP port 3000 and bind to all interfaces by default. The few important MIME types are assigned 
 and the document root (the base directory that is used for all requests) is set. The files in the document root have to be  
 readable by the user starting the web server. 

 First, check that your config is ok: 


 <pre> 

 

 {{{ 
 $ lighttpd -t -f lighttpd.conf 
 </pre> 


 }}} 

 Now start the server for testing: 


 <pre> 

 

 {{{ 
 $ lighttpd -D -f lighttpd.conf 
 </pre> 


 }}} 

 and point your browser to  

 http://127.0.0.1:3000/ [http://127.0.0.1:3000/] 

 To stop the server again, just press ctrl-c. 


 h3. 

 === A real daemon 


 === 

 Next you should familiarize yourself with some settings necessary for your server's security: 


 <pre> 

 

 {{{ 
 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" 
 ) 

 static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) 
 index-file.names = ( "index.html" ) 
 </pre> 


 }}} 

 Now the web server is listening on port 80, the default for HTTP traffic, and will switch to the user {{{www}}@www@} {{{www}}} and the group {{{www}}@www@}. {{{www}}}. 
 The server has to be started as root to take control of port 80, but it's not necessary or a good idea to continue running as root after port acquisition. 

 Lastly, we forbid access to the source of some types of files which will be used later for generating dynamic content, and we rewrite 
 all requests to a directory to the {{{index.html}}@index.html@} {{{index.html}}} file in that directory. 

 Assuming you have already created the {{{/etc/init.d/lighttpd}}} service as described in TutorialInstallation, place the config file in {{{/etc/lighttpd/lighttpd.conf}}} and start the server with: 


 <pre> 

 

 {{{ 
 # /etc/init.d/lighttpd start 
 </pre> 


 }}} 

 To stop it use: 


 <pre> 

 

 {{{ 
 # /etc/init.d/lighttpd stop 
 </pre> 



 h2. }}} 

 == 10 minutes 


 == 

 Conditionals, conditionals, conditionals: 

 The most important part in Lighty's configuration is the use of conditionals. Using simple comparisions or regular expressions, they control 
 if a default setting will be overridden or not. 


 <pre> 

 

 {{{ 
 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" 
 ) 

 static-file.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/" 
 } 

 </pre> 


 }}} 

 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 will also have a download area which will use the built-in directory listing feature: 


 <pre> 

 

 {{{ 
 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" 
 ) 

 static-file.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" 
   } 
 } 
 </pre> 


 }}} 

 As you can see, conditonals can be nested: only the {{{download}}@download@} {{{download}}} folder and its subfolders have the directory listings 
 enabled. 

 Now that we've covered the basics, you're ready to learn some more advanced topics like "includes":http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes [http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes includes] and configuring PHP with "FastCGI":http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI. 


 h2. [http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI FastCGI]. 

 == After 30 minutes 


 == 

 Now you know the basic setup, include files, and maybe even how to set up PHP or Ruby. But there's so much more to find out. 

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

 For the *configuration '''configuration file syntax* syntax''' and the complete *list '''list of configuration options* options''' [[br]]visit the reference section of the wiki:[[br]] "Reference Documentation":http://trac.lighttpd.net/trac/wiki#ReferenceDocumentation [http://trac.lighttpd.net/trac/wiki#ReferenceDocumentation Reference Documentation] 

 Also check out our community "Community":http://trac.lighttpd.net/trac/wiki#Community 
 [http://trac.lighttpd.net/trac/wiki#Community Community]