-->
Previous Table of Contents Next


Database Management File Authentication

You also can configure Apache to use DBM files for faster password and group-membership lookups. To use a DBM file, you must have the mod_auth_dbm module compiled into the server.

DBM files are UNIX file types that implement a fast hash table lookup, making them ideal for handling large user/password databases. The flat-file systems require parsing the password file for every access until a match is found, potentially going through the entire file before returning a “can’t find that user” error. Hash tables, on the other hand, know instantly whether a “key” exists in the database and what its value is.

Some systems use the ndbm libraries; some use the berkeley db libraries. However, the interface through Apache is exactly the same.

To use a DBM file for the database rather than a regular flat file, you use a different directive—AuthDBMUserFile—instead of AuthUserFile. Likewise, for the group file, AuthDBMGroupFile is used instead of AuthGroupFile.

Virtual Hosts

Apache implements a very clean way of handling virtual hosts, which is the mechanism for being able to serve more than one host on a particular machine. Due to a limitation in HTTP, serving multiple hosts is now accomplished by assigning more than one IP number to a machine and then having Apache bind differently to those different IP numbers. For example, a UNIX box might have 204.122.133.1, 204.122.133.2, and 204.122.133.3 pointing to it, with www.host1.com bound to the first, www.host2.com bound to the second, and www.host3.com bound to the third.


TIP:  Apache 1.2 and above, via the HTTP 1.1 protocol specification, supports non-IP based virtual hosts as well. With this new feature, you no longer have to provide an IP address for each virtual host.

Virtual hosts are configured by using a container in httpd.conf. They look something like this:


<VirtualHost www.host1.com>

DocumentRoot /www/htdocs/host1/

TransferLog logs/access.host1

ErrorLog logs/error.host1

</VirtualHost>

The attribute in the VirtualHost tag is the host name, which the server looks up to get an IP address.


NOTE:  If there’s any chance that www.host1.com can return more than one number or that the Web server might have trouble resolving the host name to an IP number at any point, you might want to use the IP number instead.

Any directives put within the VirtualHost container pertain only to requests made to that host name. DocumentRoot points to a directory that presumably contains content specifically for www.host1.com.

Each virtual host can have its own access log, its own error log, its own derivative of the other logs out there, its own Redirect and Alias directives, its own ServerName and ServerAdmin directives, and more. In fact, the only things a virtual host server can’t support out of the core set of directives are

ServerType MaxRequestsPerChild
UserId BindAddress
GroupId PidFile
StartServers TypesConfig
MaxSpareServers ServerRoot
MinSpareServers

If you plan to run Apache with a large number of virtual hosts, you need to be careful to watch the process limits. For example, some UNIX platforms allow processes to open only 64 file descriptors at once. Because an Apache child will consume one file descriptor per logfile per virtual host, 32 virtual hosts—each with its own transfer and error log—would quickly cross that process limit. You’ll notice when you’re running into problems of this kind if your error logs start reporting such errors as unable to fork(), or your access logs aren’t getting written to at all. Apache does try to call setrlimit() (a system function call to try to limit processes) to handle this problem on its own, but the system sometimes prevents it from making the system call successfully.

Customized Error Messages

Apache can give customized responses in the event of an error. This is controlled by using the ErrorDocument directive. The syntax is as follows:


ErrorDocument HTTP_response_code action

HTTP_response_code is the event that triggers the action. The action can be

  A local URI to which the server is internally redirected
  An external URL to which the client is redirected
  A text string that starts with a " character and where the %s variable contains any extra information, if available

For example,


ErrorDocument 500 "Ack! We have a problem here: %s.

ErrorDocument 500 /errors/500.cgi

ErrorDocument 500 http://backup.myhost.com/

ErrorDocument 401 /subscribe.html

ErrorDocument 404 /debug/record-broken-links.cgi

Two extra CGI variables are passed to any redirected resource: REDIRECT_URL contains the original URL requested, and REDIRECT_STATUS gives the original status that caused the redirection. This will help the script if its job is to try to figure out what caused the error response.

Assorted httpd.conf Settings

A few additional configuration options just don’t fit in anywhere else, because their functionality is a bit unique or different. These options include BindAddress, PidFile, and Timeout.


Previous Table of Contents Next