Master lighttpd – the lightweight alternative to Apache
Is your Apache web server too slow? Koen Vervloesem shows you how to use lighttpd instead. This lightweight web server alternative is perfect for virtual private servers and ageing hardware solutions…
Lists
So let’s give some examples of lists in the configuration file. One of the first things you’ll want to set is the list of index files.
For example:
index-file.names = ( “index.html”, “index.htm”, “default.html”, “default.htm” )
Now when someone navigates with his browser to your website’s root, eg www.example.org, lighttpd tries to find files www.example.org/index.html, www.example.org/index.htm and so on. If you’re running a PHP website such as a WordPress blog, just add ‘index.php’ to the list. Note that lighttpd tries the different filenames in the order they appear in the list until it finds a file with this name (or not).
Another interesting list is the list of file extensions that will be denied access to. For example, if you’re editing files on your web server with Vim or Emacs, chances are that there will be some backup files lingering (with their name ending on ~), which you wouldn’t want to disclose on the web.
Other files that shouldn’t be shown are .inc files. So we deny access to these files:
server.modules = ( “mod_access”, “mod_alias”, “mod_accesslog” )
These are the minimal modules you’ll need to get a decent web server experience. Other modules, like mod_rewrite, mod_redirect, mod_compress, mod_webdav and so on, can be enabled by adding them to the list. But remember: only load modules that you need, because every module needs memory, uses your processor’s resources and opens a potential security hole.
Each module has some variable to configure its behaviour. You can configure all this in the /etc/lighttpd/lighttpd.conf file, but this soon becomes messy. That’s why some distributions, eg Debian, have two directories – conf-available and conf-enabled – in /etc/lighttpd.
The directory conf-available contains a series of .conf files, which contain configuration directives to load specific modules. Some examples that Debian installs are (the filenames speak for themselves) 05-auth.conf, 10-cgi.conf, 10-fastcgi.conf, 10-rrdtool.conf, 10-ssl.conf, 10-status.conf and 10-userdir.conf. The numbers in the filenames define the order in which the configuration files are loaded.
Let’s look at 10-status.conf as an example. This file has (without the comment lines) the following content:
server.modules += ( “mod_status” ) status.status-url = “/server-status” status.config-url = “/server-config” status.statistics-url = “/server-statistics” status.enable-sort = “enable”
So all configuration directives for this module are kept together in one file. The first line adds mod_status to the list of modules that is initialised in lighttpd.conf, while the other lines set some preferences of the module. Now if you want to enable the mod_status module, you just have to execute the following commands:
/usr/sbin/lighty-enable-mod status /etc/init.d/lighttpd force-reload
The first command creates a symbolic link in /etc/lighttpd/conf-enabled to the .conf file in /etc/lighttpd/conf-available. The second command tells lighttpd to reload its configuration, after which it loads the enabled module, because at the end of /etc/lighttpd/lighttpd.conf there’s a line that says to include all configuration files in /etc/lighttpd/conf-enabled. The result is that you can see a page with the status of your web server on www.example.org/server-status. Disabling a module is equally easy to do: simply run lighty-disable-mod with the module as its argument and then reload the lighttpd configuration.
Return to the Linux User & Developer homepage















I like lighttpd but it has one serious issue why I don’t use it in production. It is not standard part of CentOS and RedHat distribution (official RPM package is not available). :-(
Thanks for a really interesting article about lighttpd (or “lighty”).
It’s so easy to just use the default Apache when setting up something.
Maybe lighttpd is _the_ alternative when it comes to older systems.
Bookmarked this for future reference.
//Michael.
I have never tested lighttpd, but to avoid the big resource consumer Apache.
I am running Nginx as a reverse proxy with Apache behind.
Here is how I configured it to run Drupal with Boost:
http://www.go2linux.org/linux/2010/04/how-install-nginx-run-drupal-boost-arch-linux-server-727