Table of Contents


1 .- Introduction

Lighttpd is a web server operating systems for Unix / Linux and Microsoft Windows. This server also known as Light year, is an alternative for the Apache web server.

This diseado to be safe, quick (very quick to tell the truth), compatible with the standards and flexible at the same time that this optimized for environments where speed is critical. Its memory footprint is very small (in comparison to other web servers), a light load on the CPU speed and his approach makes perfect lighttpd server load too.

2 .- Installation on Debian

To install lighttpd, type, as root:

  deathbian: ~ # aptitude install lighttpd 

Note: On Debian Lenny, lighttpd runs with the user www-data, and not lighttpd.

3 .- Basic Configuration

The install on Debian provides us with the configuration files and boot Light year, but if you need some examples

file: / etc / lighttpd / lighttpd.conf

  # Debian lighttpd configuration file 
 # 

  ############ Options you really have to take care of #################### 

  # # Modules to load 
  # Mod_access, mod_accesslog and mod_alias are loaded by default 
  # All other module should only be loaded if neccesary 
  # - Saves some time 
  # - Saves memory 

  server.modules = ( 
              "mod_access" 
              "mod_alias" 
              "mod_accesslog" 
              "mod_compress" 
              "mod_fastcgi" 
  # "Mod_rewrite" 
  # "Mod_redirect" 
  # "Mod_status" 
  # "Mod_evhost" 
  # "Mod_usertrack" 
  # "Mod_rrdtool" 
  # "Mod_webdav" 
  # "Mod_expire" 
  # "Mod_flv_streaming" 
  # "Mod_evasive" 
  ) 

  fastcgi.server = (. "php" => (( 
                      "bin-path '=>" / usr / bin / php-cgi " 
                      "socket" => "/ tmp / php.socket" 
                  ))) 
  # # A static document-root, for virtual-hosting take look at the 
  # # * Server.virtual-options 
  server.document-root = "/ var / www /" 

  # # Where to send messages to error - 
  server.errorlog = "/ var / log / lighttpd / error.log" 

  # # Files to check for if ... / is requested 
  index-file.names = ( "index.php", "index.html" 
                                 "index.htm", "default.htm" 
                                 "index.lighttpd.html") 

  # # Use the "Content-Type" extended attribute to obtain mime type if possible 
  # Mimetype.use-xattr = "enable" 

  # # # # Accesslog module 
  accesslog.filename = "/ var / log / lighttpd / access.log" 
  # # Deny access the file-extensions 
 # 
  # ~ Is for backupfiles from vi, emacs, joe, ... 
  #. Inc is often used for code which includes in general should not be part 
  # Of the document-root 
  url.access-deny = ( "~". "inc") 

  # # 
  # Which extensions should not be handle via static-file transfer 
 # 
  #. Php,. Pl,. Fcgi are most often handled by mod_fastcgi or mod_cgi 
  file.exclude-static-extensions = (. "php". "pl", ". fcgi") 

  ######### Options that are good but not to be neccesary to be changed ####### 

  # # Bind to port (default: 80) 
  # Server.port = 81 

  # # Bind to localhost only (default: all interfaces) 
  # # Server.bind = "localhost" 

  # # Error-handler status for 404 
  # server.error-handler-404 = "/ error-handler.html" 
  # server.error-handler-404 = "/ error-handler.php" 

  # # To help the rc.scripts 
  server.pid-file = "/ var / run / lighttpd.pid" 

  # # 
  # # Format:   . html 
  # # -> ..../status-404.html For 'File not found' 
  # server.errorfile-prefix = "/ var / www /" 

  # # Virtual directory listings 
  listing.encoding-dir = "utf-8" 
  server.dir-listing = "enable" 

  # # Send-header unhandled HTTP headers to error-log 
  # debug.dump-unknown-headers = "enable" 

  # # # Only root can use these options 
 # 
  # Chroot () to directory (default: no chroot ()) 
  server.chroot = # "/" 

  # # Uid to change   (Default: do not care) 
  server.username = "www-data" 

  # # Uid to change   (Default: do not care) 
  server.groupname = "www-data" 

  # # # # Compress module 
  compress.cache-dir = "/ var / cache / lighttpd / compress /" 
  compress.filetype = ( "text / plain", "text / html", "application / x-javascript", "text / css") 

  # # # # Status module 
  # Status.status-url = "/ server-status" 
  # Status.config-url = "/ server-config" 

  # # # # Url handling modules (rewrite, redirect, access) 
  Url.rewrite # = (= "^/$"> "/ server-status") 
  # Url.redirect = ( "^ / wishlist /(.+)" =>" http://www.123.org/ $ 1 ") 

 # 
  # Define a pattern for the host url finding 
  #%% =>% Sign 
  #% 0 => + domain name tld 
  #% 1 => tld 
  #% 2 => domain name without tld 
  #% 3 => 1 subdomain name 
  #% 4 => 2 subdomain name 
 # 
  # Evhost.path-pattern = "/ home / storage / dev / www /% 3/htdocs /" 

  # # # # End module 
  # Expire.url = ( "/ buggy /" => "access 2 hours", "/ asdhas /" => "access plus 1 seconds 2 minutes") 

  # # # # Rrdtool 
  Rrdtool.binary # = "/ usr / bin / rrdtool" 
  # Rrdtool.db-name = "/ var / www / lighttpd.rrd" 

  # # # # Handle Debian Policy Manual, Section 11.5. urls 
  # # # # And by default allow them only from localhost 

  $ HTTP [ "remoteip"] == "127.0.0.1" ( 
          alias.url + = ( 
                  "/ doc /" => "/ usr / share / doc /" 
                  "/ images /" => "/ usr / share / images /" 
         ) 
          $ HTTP [ "url"] = ~ "^ / doc / | ^ / images /" ( 
                  listing.activate-dir = "enable" 
          ) 
  ) 

  # # # # Variable usage: 
  # # Variable name without. "  is by car prefix "var."  and becomes "var.bar" 
  bar = 1 # 
  # var.mystring = foo 

  # # Integer add 
  # + = 1 bar 
  # # String concat, with integer cast as string, result: "www.foo1.com" 
  server.name # = "www."  Var.bar mystring + + +. "Com" 
  # # Array merge 
  # index-file.names = (foo +. "php") + index-file.names 
  # index-file.names + = (foo +. "php") 

  # # # # External configuration files 
  # # Mimetype mapping 
  include_shell "/ usr / share / lighttpd / create-mime.assign.pl" 

  # # Load enabled configuration files, 
  # # Read / etc / lighttpd / conf-available / README first 
  include_shell "/ usr / share / lighttpd / include-conf-enabled.pl" 

  $ SERVER [ 'socket'] == "443" ( 
    ssl.engine = "enable" 
    ssl.pemfile = "/ etc / ssl / certs / lighttpd.pem" 
  ) 

With Light installed and working properly and we are not going to use Apache 1.3/2.x, so what better remove the system (Remember to make backup data and Apache configuration files), typing:

  deathbian: ~ # aptitude remove apache2 

3.1 .- Setting the directives of national lighttpd

  • server.document-root = / var / www / html specifies the directory by default to the sites.
  • server.port = 80 Specifies the default port for the server.
  • server.username = www-data user in Debian on which runs Light year.
  • server.groupname = www-data Specifies the user name and group with which starts / stops the server daemon lighttpd. This is a safety feature, so in this manner does not run with root privileges.
  • server.bind = server-ip-address specifies the IP address of the server. So it is also possible to enter a hostname or localhost.
  • server.tag = lighttpd is used to assign the name and version number of lighttpd (default). This is a safety feature. You can configure this way:
      server.tag = "My web server v1.0" 

    Note: This is the name that brings the server in response to his bedside. You can check by using Netcraft.

  • server.errorlog = / var / log / lighttpd / error.log Specifies the log file of error.
  • accesslog.filename = / var / log / lighttpd
  • Specifies the log file accesses, which can be used by an application of statistics of visitors as webalizer.
  • index-file.names = (index.php, index.html) A listing of files in each directory by default.
  • server.modules = (
    Mod_access,
    Mod_accesslog,
    Mod_fastcgi,
    Mod_rewrite,
    Mod_auth
    ): The modules described above will be the only charge that Light year. Of course it is possible to add more. From here the secret of speed and low memory consumption on the server, we see a more detailed description:

    • mod_access: The access module is used to deny access to certain files.
    • mod_accesslog: Used to write the blog CLF, flexible apache.
    • mod_fastcgi: Support for FastCGI Perl / PHP etc.
    • mod_rewrite: Necessary to rewrite Url's SEO compatible.
    • mod_auth: Authentication, usually for password-protected directories.
  • mimetype.assign = (
    . Pdf => application / pdf,
    . Sig => application / pgp-signature
    ): Used to allocate the mapping of the Mimetype.

Edit the file / etc / lighttpd / lighttpd.conf and all the directives set out above.

  deathbian: ~ # vim / etc / lighttpd / lighttpd.conf 

4 .- Checking the web service

Since everything is configured to our needs we will save the file and start the daemon lighttpd:

  deathbian: ~ # / etc / init.d / lighttpd start 

If you want to check which services are running and on which port to verify the successful installation of our lighttpd, type:

  deathbian: ~ # netstat-ntulp 
  Active Internet connections (servers only) 
  Proto recv-Q Send-Q Local Address Foreign Address State PID / Program name 
  tcp 0 0 127.0.0.1:3306 0.0.0.0: * LISTEN 2522/mysqld 
  tcp 0 0 0.0.0.0:111 0.0.0.0: * LISTEN 2151/portmap 
  tcp 0 0 0.0.0.0:80 0.0.0.0: * LISTEN 2720/lighttpd 
  tcp 0 0 0.0.0.0:113 0.0.0.0: * LISTEN 2742/inetd 
  tcp 0 0 0.0.0.0:21 0.0.0.0: * LISTEN 2927/tcpsvd 
  tcp 0 0 0.0.0.0:443 0.0.0.0: * LISTEN 2720/lighttpd 
  tcp 0 0 127.0.0.1:831 0.0.0.0: * LISTEN 2775/famd 
  tcp6 0 0::: 22::: * LISTEN 2444/sshd 
  udp 0 0 0.0.0.0:32768 0.0.0.0: * 2432/lwresd 
  udp 0 0 0.0.0.0:32770 0.0.0.0: * 2793/avahi-daemon: 
  udp 0 0 0.0.0.0:517 0.0.0.0: * 2742/inetd 
  udp 0 0 0.0.0.0:518 0.0.0.0: * 2742/inetd 
  udp 0 0 127.0.0.1:921 0.0.0.0: * 2432/lwresd 
  udp 0 0 0.0.0.0:5353 0.0.0.0: * 2793/avahi-daemon: 
  udp 0 0 0.0.0.0:111 0.0.0.0: * 2151/portmap 
  udp6 0 0::: 32769::: * 2432/lwresd 

Now go to your browser, either Firefox or Internet Explorer and verify that our new website accessible via web, type in the address bar of your browser
http://localhost/ or http://127.0.0.1/

5. Final words

From personal experience, I can assure you that the performance of Apache is much lower compared to lighttp.

Light may be very young (in comparison to other systems, web servers), their search for responding to the reality of our days, the web2.0 which requires higher performance for sites with thousands of visitors daily.

Over the next few days will post items like;

Optimizing the web server lighttpd

  • Configuring PHP FastCGI on lighttpd
  • Configuration of virtual hosting on lighttpd
  • Compile and optimize php scripts on lighttpd with php eAccelerator
  • Solving Problems with the cache eAccelerator

Strengthening the security of lighttpd

  • Extreme Web server security: Setting lighttpd, php, perl, MySQL with support for an environment of virtual file system (chrooted jail)
  • SSL Configuration
  • Create and use our own SSL certificate in lighttpd
  • With password protection; to directories

Miscellaneous configuration lighttpd

  • Installing and configuring the statistics Webalizer for lighttpd
  • URLs for wordpress SEO compatible with lighttpd
  • Deny direct links or theft of images (leeching) with lighttpd

Monitoring server lighttpd

  • Monitor and restart the service lighttpd when it crashes.

Popularity: 25% [?]