Serving a single static website

Where to store websites?

The question of where to store a web site on a server, for anything but the most trivial of sites, is in many ways a simple one. As this guide is mostly dedicated to virtual hosting we shall assume that for administrative convenience a separate partition, or in our example a new logical volume, will be used. The example below shows how to create a 1GB logical volume and format it with the ext3 filesystem.

lisa lvcreate volumes -n web-mad-hacking -L 1G
lisa mkfs.ext3 /dev/volumes/web-mad-hacking

As you can see from the above example we have accepted the default options when creating the filesystem. When we mount it we can use the options shown below to reduce access times by disabling recording of access times for both files and directories.

/etc/fstab
/dev/volumes/web-mad-hacking    /var/www/mad-hacking    ext3    noatime,nodiratime    0 2

All which then remains is to mount the new volume, using a command similar to that shown below, and populate the new filesystem with the files we wish to serve from our web site. As you can see we using a sub-directory called website so that we can easily separate CGI scripts, JavaWeb Applications, etc from other content.

lisa mkdir /var/www/mad-hacking
lisa mount /var/www/mad-hacking
lisa mkdir /var/www/mad-hacking/website

Configuring the default virtual host

The default configuration supplied by the Gentoo developers with the apache package enables name-based virtual-hosting support by default. We shall cover name-based and address-based virtual-hosting in the next two sections of this guide. For now, if all we wish to do is serve a single static web site, then we can simply modify the definition of the default virtual host as shown below.

/etc/apache2/vhosts.d/default_vhost.include
ServerAdmin spamcatcher@hacking.co.uk

DocumentRoot "/var/www/mad-hacking/website"

<Directory "/var/www/mad-hacking/website">
Options Indexes
Order allow,deny
Allow from all
</Directory>
Information:
We have enabled the Indexes option to aid in configuring the server to correctly serve content. If allowing users to view an index of any directory on your web site is not desirable, which it rarely is, this option can be removed. We cover how to enable directory listings on a per directory basis later on in this guide.
 

Once we have modified the configuration for the default virtual host we need to signal the apache daemon to reload its configuration files.

lisa /etc/init.d/apache2 reload

You can verify that this is working by placing a web site at the path we have just configured and pointing a web browser at the host we used for the installation.

http://web/