Fast and safe with the Hiawatha secure web server

Service Warehouse

The next thing Hiawatha needs to know is which website to serve up. To define the website, you first specify the subdirectory with the files. Apache users will be familiar with this directory as DocumentRoot, but Hiawatha calls it WebsiteRoot:

WebsiteRoot = /usr/local/var/www/hiawatha

In principle, you can select any folder on your disk; you will find a sample index.html file below /usr/local/var/www/hiawatha. Hiawatha needs the name (or alternatively the IP address) on which the website will be accessible:

Hostname = www.mywebsite.com

This detail is particularly important if you are using virtual hosts (see the box titled "Virtual Hosts" for more details). If you use IPv6 addresses, just use them; you can even mix them with IPv4 addresses.

That's it. This minimal configuration contains just six lines. Listing 1 is a complete httpd.conf file. Comments start with a pound sign, as in shell scripts.

Listing 1

Minimal Configuration for Hiawatha

 

Kick Starter

Just to see whether the configuration is working, launch the web server with the following command:

sudo hiawatha

If you receive an error message:

Error binding IP_address

either Hiawatha does not have sufficient privileges (for ports below 1024) or a competing web server is already listening on the same port. A competing web server is actually a common occurrence if you are using a distribution that comes with a pre-configured web server, such as Apache. In that case, you can either change the port or stop the competitor. To stop Apache in Ubuntu, for example, you could enter the command

sudo /etc/init.d/apache2 stop

although you might still see an error message:

Warning: can't write PID file /usr/local/var/run/hiawatha.pid

The preceding message says that Hiawatha does not have access privileges for the /usr/local/var/run directory; one common cause for this message is that the directory just doesn't exist. You can either create the directory manually or live with the error message for the time being. The web server simply stores its process ID in the specified PID file. Alternatively, you can use httpd.conf to point to a different file location:

PIDFile=<filename>

Launching a browser and pointing to localhost will tell you if Hiawatha is running properly. You should see the test page shown in Figure 1.

A kill signal, as in

<C>sudo killall hiawatha<C>

will stop Hiawatha. Of course, this is a fairly brutal approach, and it is not very elegant if you are thinking of adding the web server startup to your distribution's boot process. The hiawatha script included in the extras subdirectory below the source code directory gives you a more elegant approach to launching and stopping Hiawatha, but you should be aware of a couple of obstacles. First, the script assumes that the web server was able to create the PID file. Also, the script is designed for Debian. If you want to run the script on any other distribution, you need to modify the paths in the first four lines to match your local conditions.

Going Walkabout

As you would expect of a modern web server in these Web 2.0 times, Hiawatha supports the execution of CGI programs. Of course, the administrator first has to explicitly enable this feature

ExecuteCGI = yes

and then specify which file suffix the CGI programs will have:

CGIextension = cgi

In the case of scripts, such as PHP or Python applications, Hiawatha also needs the name and path for the interpreter:

CGIhandler = /usr/bin/php5-cgi:php,php5

When Hiawatha finds a file with a .php or .php5 suffix, it will launch the php5-cgi interpreter in the /usr/bin folder and pass the script in to it. The same approach is used for other script languages:

CGIhandler = /usr/bin/perl:pl
CGIhandler = /usr/bin/python:py

To prevent buggy or malicious CGI programs or scripts from crashing or hijacking the computer, you should restrict their run time. A value of five seconds should do for a start:

TimeForCGI = 5

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News