While a large proportion of the world's webservers are currently using Apache, a competitor has been steadily gaining popularity on many high-usage sites.
Lighttpd, pronounced "lighty", is a small-footprint, high-speed webserver, and is notably used by sites such as
Sourceforge,
YouTube and
MiniNova. Netcraft state that Lighttpd is currently being used on
1.38 million sites, and is steadily gaining on Sun's share of the market. This introductory article provides a guide to getting Lighttpd installed and configured.
SSL
When we originally compiled Lighttpd, we didn't enable any SSL support, so we'll have to recompile it:
./configure --prefix=/usr/local/lighttpd --with-openssl
make
su
make install
Obviously, we would need the OpenSSL libraries and headers installed, in order for this to compile. Under Debian and Ubuntu Linux, these can be found in the
libssl0.9.8 and
libssl-dev packages. Fedora and Redhat keep them in the
openssl and
openssl-devel packages.
Now, we can enable SSL in the configuration file with the following:
ssl.engine = "enable"
ssl.pemfile = "/usr/local/lighttpd/etc/server.pem"
ssl.ca-file = "/usr/local/lighttpd/etc/ca.crt"
The
server.pem and
ca.crt files are created either by using the
openssl utility, or by obtaining a signed-certificate from a certificate authority.
The above configuration will make the running webserver SSL only, and furthermore, it will be running on port 80, as we set up earlier, which probably isn't what we want. To run both SSL and non-SSL HTTP at the same time, we can use a conditional, and put SSL on port 443:
$SERVER["socket"] == "0.0.0.0:443" {
ssl.engine = "enable"
ssl.pemfile = "/usr/local/lighttpd/etc/server.pem"
ssl.ca-file = "/usr/local/lighttpd/etc/ca.crt"
}
Obviously, if we wanted our SSL content to be different to that which we're serving on our non-SSL port, we would just insert a different
document-root within the $SERVER["socket"] block.
FastCGI
Static webpages are all very nice, but there's likely to be a point where we want our website to be more interactive. Lighttpd doesn't serve any dynamic content itself; rather, it hands it off to a FastCGI handler.
To use php with lighttpd, we must ensure that it has been compiled with FastCGI support; Debian and Ubuntu both provide a
php-cgi package with the correct compile time options set; in Redhat and Fedora, the
php-cli package contains the required binary.
The following will configure Lighttpd to pass php pages off to the php4-cgi binary. Be sure to update the
index-file.names directive so that it picks up
index.php as an index page:
index-file.names = ( "index.php", "index.html", "index.htm" )
fastcgi.server = ( ".php" =>
(( "socket" => "/usr/local/lighttpd/var/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-cgi"
))
)
FastCGI servers don't have to sit on the same host as our webserver; it's quite simple to tell Lighttpd to forward requests to a server elsewhere:
fastcgi.server = ( ".php" =>
(( "host" => "10.1.8.200",
"port => "8080"
))
)
There's a number of additional options that can be given in the
fastcgi.server directive. For locally spawned servers,
min-procs sets the minimum number of processes started, while
max-procs puts an upper limit on the number that can be spawned.
idle-timeout sets the time, in seconds, after which an idle process will be terminated.
Next time...
We've covered a fairly wide range of areas within Lighttpd that you might like to start off investigating. In the next tutorial, we'll cover more advanced features of Lighttpd, such as proxying, rewriting urls, complex virtual hosting and authentication.
If you found this article helpful, consider making a donation to offset the costs of running this server, to one of these addresses: