Project

General

Profile

TutorialConfiguration » History » Revision 7

Revision 6 (Anonymous, 2006-02-19 15:10) → Revision 7/28 (Anonymous, 2006-03-26 20:33)

= Configuration = 

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

 == 5 minutes == 

 Want You want to run a fast, low-resource server for static content? It's easy: 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 TCP port 3000 3000/tcp and bind to all interfaces by default. The few important MIME types mimetypes are assigned 
 and the document root document-root (the base directory direcorty that is used for all requests) is set. The files in the document root document-root have to be  
 readable by the user starting the web server. webserver. 

 First, check that your config is ok: 

 {{{ 
 $ lighttpd -t -f lighttpd.conf 
 }}} 

 Now start the server for testing: 

 {{{ 
 $ lighttpd -D -f lighttpd.conf 
 }}} 

 and point your browser to  

 [http://127.0.0.1:3000/] 

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

 === A a real daemon === 

 Next As you should familiarize yourself with some settings necessary for your server's 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" 
 ) 

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

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

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

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

 {{{ 
 $ /etc/init.d/lighttpd start 
 }}} 

 To stop it use: 

 {{{ 
 $ /etc/init.d/lighttpd stop 
 }}} 

 ( this assumes that you have created that service already as described in TutorialInstallation ) 

 == 10 minutes == 

 Conditionals, conditionals, conditionals: 

 The most important part in Lighty's lighties configuration is the use of conditionals. Using They control via simple comparisions or regular expressions, they control regexes 
 if a default setting will be overridden 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" 
 ) 

 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/" 
 } 

 }}} 

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

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

 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" 
   } 
 } 
 }}} 

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

 Now that we've covered the basics, you're With this basic steps you are ready to learn some more advanced topics like [http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes includes] and configuring PHP with [http://www.lighttpd.net/documentation/fastcgi.html FastCGI]. read on the other chapters about: 

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

 == After after 30 minutes == 

 Now you know the basic setup, include files, includes and maybe even how to set up PHP might have php or Ruby. But there's so much ruby already running. There is alot more to find out. 

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

 You can The website also check has the [http://www.lighttpd.net/documentation/ online manual] and its [http://www.lighttpd.net/documentation/configuration.html manual online: 

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

 as starting point for the configuration.