Table of Contents

An Introduction to the Apache Configuration File

The apache web service is usually run as a system service (which in Unix is known as a daemon process). As it implements the hypertext transfer protocol (HTTP) and runs as a daemon process, the executable program that runs the apache web server is the http daemon or httpd (httpd.exe on windows). In common with many applications that originated in to Unix world, httpd is configured by a text-based configuration file which is by default namedhttpd.conf. In this document, we shall introduce httpd.conf using the XAMPP platform configuration on Windows and Linux as an example. You should note that other platforms, for example Ubuntu, SuSE, Fedora or Macintosh OS X, will have slightly different settings, but also that these differences are largely due to variations in the installation locations that are used for these distributions. Please feel free to extend this page to describe these.

Some Important Definitions

Before we explore the configuration of an Apache we server, there are some important concepts that we need to define.

Locating the configuration file

In order to explore httpd.conf, you first need to find it!

When you have found the file, open it in your favourite text editor.1)

Exploring the Apache Configuration

A typical Apache web server installation will consist of four directories:

Standard settings

The configuration of the Apache web server will have several predefined settings. These are:

Server Directives

Apache provides a large number of directives for controlling how the server will work

Directory Aliasing

To avoid everything having to be located in DocumentRoot you use an alias:

Alias /marketing /home/marketing

This essentially defines a URI redirection. If the URI /marketing is requested, the server will look for files in /home/marketing rather than htdocs/marketing. A <Directory> directive would normally be required to specify access rights for /home/marketing.

User Directories

UserDir is a special directive which allows you to set up user-owned web sites. These are indicated by special location /~user. The actual directory used will depend on your operating system. In Linux it is usually /home/user/public_html. Global settings can be defined by server and overridden (if allowed) by an .htaccess file in ~/public_html.

Authentication

Apache provides a simple mechanism for authentication and authorisation. Additional modules add sophistication.

An example:

Alias /marketing /home/marketing
<Directory /home/marketing>
  AuthType basic
  AuthName "sales people"
  AuthUserFile some_dir/sales
  AuthGroupFile some_dir/groups
  Require valid-user # or valid-group  
</Directory>

The example <Directory> directive shows an example of the settings that define “basic authentication”. When a client attempts to access a resource in directory /marketing a “401 unauthorized” message is sent back. The client's browser shows a simple login page (user_name password). The user's credentials are returned to the client as the data in a WWW-Authentication field . If the password supplied matches user_name’s password (stored in some_dir/sales) authentication is passed and access granted.

The password file is created using <ServerRoot>/bin/htpasswd. It is similar in format to the password file (/etc/passwd) used in Unix. The Groups file is just a file containing group records each of which contains a list of users who belong to that group of the form:

 marketing: chris ellie joe 

Server Logs

By default, the apache web-server keeps a log of every successful request and errors that occur. The location of the log files is defined in httpd.conf.

The types of data that can be logged include:

Usually, each log is kept in a separate file (e.g. error.log, access.log, referrer.log) but you can use server directives to turn off certain logs, provide more or less detail, or even to direct all logging messages to a single file.

Once your web site has been running for a while, you will, as a web master, want to examine the log files. The types of analysis you can do include:

On XAMPP, such data is accessible on XAMPP through the Webalizer.

Rest of the Story

Apache contains many more directives. You will see some first hand in the EG-253 lab exercises.

A Typical VirtualHost Definition

Virtual hosts can be set up which allows the appearence of multiple hosts on a single IP address. Here's an example that sets up a fully qualified domain name marketing.mycompany.com. This host will have its own settings for SeverAdmin, DocumentRoot, ServerName, ErrorLog and TransferLog.

 <VirtualHost marketing.mycompany.com>
   ServerAdmin sales@mycompany.com
   DocumentRoot /opt/lampp/htdocs/marketing
   ServerName marketing.mycompany.com
   ErrorLog /opt/lampp/logs/marketing/error_log
   TransferLog /opt/lampp/logs/marketing/access_log
 </VirtualHost

A corresponding HTTP request for a resource located on this virtual host would be:3)

  GET /catalogue.pdf HTTP/1.1
  Host: marketing.mycompany.com

Homework Exercise

A real httpd.conf file is fairly complex, but it is usually well documented and as it is text, it's fairly easy to read. Examine the configuration file of your web server (XAMPP for Linux: /opt/lampp/httpd.conf; XAMPP for Windows c:\xampp\apache\conf\httpd.conf). Open the file, and then

  1. Determine the User and Group of your server
  2. Note the location of your log files, mime types, ServerRoot, DocumentRoot etc.
1)
You may need to be an administrator to access the file
2)
This can be changed by use of Virtual Directories – see the Alias and Directory directives
3)
assumes registration of the host IP for marketing with the authoritative name server for mycompany.com.