|
AOLServer |
Apache |
Microsoft IIS |
Netscape iPlanet 6.0 |
Netscape iPlanet 4.x |
Netscape Enterprise Server 3.6
Mod_Headers
The Apache web server provides webmasters with the ability to customize HTTP headers via the inclusion of the mod_headers module. This module is used to specify headers such as Cache-Control, to add new headers such as P3P, or to create webmaster-defined headers such as Author. Mod_headers is an extension module and therefore not available with a default installation and configuration of Apache. Webmasters who are interested in using this method must recompile Apache to include mod_headers.
Once compiled, directives can be added to the server configuration file httpd.conf or within the directory-oriented configuration file .htaccess. But first, webmasters must edit httpd.conf to ensure that the module has been successfully loaded. Under the Dynamic Shared Object (DSO) Support section of the file, the following line must be evident:
LoadModule headers_module path/to/mod_headers.so
Next, an AddModule directive must be added, as in the following:
AddModule mod_headers.c
For more information about mod_headers, go to http://httpd.apache.org/docs/mod/mod_headers.html.
Mod_Expires
Content expiration allows servers to send HTTP header information about the time an object is set to expire. This information can be used to determine whether an origin server should be queried for a fresh copy of the object. Both mod_headers and mod_expires must be compiled in order to enable content expiration. Mod_expires can be added with the same method that was used to add mod_headers.
Expires configuration is set via three directives: ExpiresActive, ExpiresByType, and ExpiresDefault. Webmasters must evaluate their expiration needs and apply them to the appropriate document realm. The directives are typically placed within the httpd.conf file, though webmasters may also place the information within .htaccess files. If the directives are used within the server configuration files, they may be used within both the Virtual Host and the Directory containers.
Enabling content expiration is accomplished through the ExpiresActive directive. If it is set to OFF, no expire headers are generated for the site. If it is set to ON, and expire headers are generated. To enable content expiration, add the following line to the appropriate file:
ExpiresActive on
The ExpiresDefault directive specifies a default expiration value for every object on the server. It takes a single time argument. Time is defined as the number of seconds from a base time, where the base time is either the client's access time (denoted by an A) or the file's last modification time (denoted by an M). The following example demonstrates the use of ExpiresDefault:
ExpiresDefault A604800
The ExpiresByType directive specifies a default expiration value per object type. The directive takes two arguments: mime type and time. The following is an example of setting a default expiration value of one week for all html files:
ExpiresByType text/html A604800
It is important to note that the ExpiresByType directive will override the value set with the ExpiresDefault directive for the specified file type only.
For more information about mod_expires, go to http://httpd.apache.org/docs/mod/mod_expires.html.
Custom Headers
Adding custom headers requires Apache to be compiled with mod_headers. Directives can be added to the server configuration file httpd.conf or within the directory-oriented configuration file .htaccess. Directory, Location, and Files are sectional containers used within httpd.conf to allow webmasters to determine whether directives apply to the site in general or to specific files or directories. This allows webmasters to decide whether the entire web site will have a particular header or if it will be necessary to use different header configurations for different sub-sites within the domain.
HTTP headers can be added using the Header directive in conjunction with one of three arguments – set, append, and add. In the following example, a webmaster wishes to set an HTTP header named Author. The action – set – is listed first, followed by the HTTP header, and then finally the value associated with that header.
Header append Author "Internet Services"
Webmasters are also able to unset headers and would use the argument unset to do so, as in the following example:
Header unset Author "Internet Services"
Webmasters may also wish to serve HTTP headers based on specified URLs. The Location directive will be used to accomplish this. The following example demonstrates how to indicate a single HTTP header for an entire site:
Header append Author "Internet Services"
The second example demonstrates two policy reference files for two sub-sites within the domain.
Header append Author "Joe Doe"
Header append Author "Jane Doe"
Apache 2.x
In addition to the previous functionality, the newest version of Apache contains enhanced caching capabilities within the mod_file_cache module. This module is an extension of the Apache 1.3 module mod_mmap_static. The purpose of this module is to reduce server load by caching static objects that do not change very often. Also keep in mind that mod_file_cache does not affect objects that have special content handlers, such as CGI programs. Finally, extreme caution should be taken when utilizing mod_file_cache on a server. Setting up caching can be complex, and doing so incorrectly will result in a broken web site.
Mod_file_cache is not a part of the default Apache installation and configuration. Prior to installing or recompiling Apache, insert the following line into the build configuration file:
AddModule modules/experimental/mod_file_cache.o
The module contains two directives: MMapFile and CacheFile. MMapFile will map one or more files into memory. These files are automatically mapped when the server is started up and automatically unmapped when the server is shut down. Mapping a file should be done in the following format:
MMapFile /path/to/htdocs/index.html
For more information about mod_file_cache, go to http://httpd.apache.org/docs-2.0/mod/mod_file_cache.html.
|