Using the thttpd Web Server.
The World Wide Web is an integral part of the Internet. In fact, in many peoples’ eyes, the Web is the Internet. Although this view is incorrect (it ignores email, FTP, and many other protocols), it does reflect the importance and visibility of the Web to average users.
Just what is the Web, though, and how is it implemented? At its core, the Web is a series of server computers that run server programs implementing the Hypertext Transfer Protocol (HTTP) and its secure variant, HTTPS. According to an ongoing Netcraft survey available at http://news.netcraft.com/archives/web_server_survey.html, the most popular Web server software by far is Apache (http://httpd.apache.org/). In January, 2006 (the latest figures available as the magazine goes to press), Apache manages almost 70% of the Web sites surveyed. The next most popular server package, Microsoft’s IIS, manages just under 21% of the Web’s sites. Apache is available for Linux — in fact, all major Linux distributions ship with Apache — so if you want to run a Web site on the market- leading package, you can do so.
Despite its hugely dominant position, though, Apache isn’t the only choice in web servers, nor is it necessarily the best choice. Apache is a large program with lots of features, which makes it very flexible. These characteristics also mean that Apache consumes a lot of resources and, at least in theory, make it more susceptible to bugs than smaller packages. (In practice, of course, other factors can affect “bugginess”; Apache isn’t necessarily any more buggy than a slimmer web server package.) If you’re running a Web site on a computer with minimal hardware or if you don’t need all of Apache’s features and would rather avoid the possibility of encountering bugs related to features you don’t use, you might want to look into alternatives.
Web Server Features
Just why is Apache such a big program? Apache supports several features that add to its size, including the ability to manage dynamic content (CGI scripts), SSL encryption, output filtering, proxy load balancing, and so on. Many of these features are important for large Web sites but are unimportant for small ones. Even much of the content served from large sites doesn’t rely on these features; such sites might combine Apache with a smaller server (perhaps running on another computer) to help reduce the load on the main Apache system.
Ideally, a lightweight web server should provide fairly basic features to avoid the size and complexity of Apache. Small Web servers sometimes have specialized features, as described shortly, but some are simple, basic, and general-purpose Web servers that simply lack the range of features provided by Apache.
Lightweight Web Server Options
So what options are there, aside from Apache? Given that Apache and IIS together hold over 90% of the Web server market, you might think that the pickings for alternatives are slim. This isn’t true, though. Quite a few options exist for Linux alone, including:
*Anti-Web HTTPD. headquartered at http://www.hcsw.org/awhttpd/, is a simple web server that nonetheless supports CGI. In its most basic mode of operation, it requires no configuration file.
*Athana. This server is unusual because it’s written entirely in Python. You can learn more at http://www.hcsw.org/awhttpd.
*EHS. The Embedded HTTP Server (EHS) isn’t a standalone program; rather, it’s a C++ class that enables you to add a complete Web server to your own C++ programs. The main EHS web page is http://www.hcsw.org/awhttpd/.
*Gatling. This web server, found at http://www.hcsw.org/awhttpd/, is designed for speed and takes advantage of platform-specific application programming interfaces (APIs) to achieve its goal.
*Screws. This server is designed to optimize extensibility rather than speed. It’s built as a small core that calls external programs to process requests. You can learn more at http://www.nopcode.org/blog/screws.html.
*thttpd. The tiny/turbo/throttling HTTP server (thttpd) is a small server that’s suitable for handling static content and CGI scripts. It’s headquartered at http://www.acme.com/software/thttpd/.
Clearly, some of these web servers are rather specialized; I’ve mentioned them to give you some idea of the wide range of web servers that are available. This list also only scratches the surface. Check http://www.linuxlinks.com/Software/Internet/WebServers/ or do a Web search on “Linux Web servers” to find more.
Because it’s a moderately popular, small, and suitable for general purpose use, let’s look at thttpd in more detail. thttpd is capable of handling a basic web site, or even one that delivers CGI content. It can’t handle SSL encryption, though. If you need SSL support, you’ll either need to use another server or use two servers, one for SSL and one for non-SSL connections. Because of its small size and efficiency, though, thttpd is excellent for use on weak computers or on more powerful systems that must handle a large number of simple requests.
Obtaining and Installing thttpd
Many Linux distributions include thttpd as part of their standard packages, but thttpd isn’t likely to be installed by default. Check your distribution’s CD-ROMs or use a network-enabled package installer, such as apt-get, yum, or emerge, to install the thttpd package for your distribution. For instance, you might type:
# apt-get install thttpd
(Of course, the details of the command you use will vary from one distribution to another.)
If you can’t find thttpd on your distribution’s list of supported packages, you can download it from the main thttpd site at http://www.acme.com/software/thttpd/. The download link is entitled” Fetch version 2.25b,” although the version number may change by the time you read this. This link points to a source code tarball. Unpack it with tar and perform the typical set of commands to compile and install the software
$ tar xvfz ~/thttpd-2.25b.tar.gz
$ cd thttpd-2.25b/
$ ./configure
$ make
$ sudo make install
The README file provides important information, so you may want to read it before you configure or build the software. Also, the installation step assumes the existence of a www group. Create the group before you type sudo make install, if it doesn’t already exist on your system.
Configuring thttpd
The thttpd server can be configured via command-line options when it starts; however, it also supports an optional configuration file. Your distribution might set up thttpd to use /etc/thttpd.conf, /etc/thttpd/thttpd.conf, or some other file by default. Look for such files or use your package management tools to find a configuration file. If you can’t find a configuration but would like to use one, tell thttpd to use the file when you configure it to launch.
A typical thttpd configuration file looks something like the one shown in Listing One.