The httpd.conf File
Despite the fact that you may change only one or two options, you need to understand how Apache is configured, what files the server requires, and where all the files are located. Given the importance of web servers for most networks, Apache is too essential for you to ignore. Additionally, the assumptions made by the distribution may not match the use you plan for your server, and you may want to fine-tune the configuration. To master Apache, you need to understand the Apache configuration file. Traditionally, Apache was configured by three files:
httpd.conf Defines configuration settings for the HTTP protocol and for the operation of the server. This includes defining what directory holds the configuration files.
srm.conf Configures how server requests are managed. This includes defining where HTTP documents and scripts are stored.
access.conf Defines access control for the server and the information it provides.
The functions of the three files overlap, and any Apache configuration directive can be used in any of the configuration files. The traditional division of the files into server, data, and security functions was essentially arbitrary. Some administrators still follow this tradition, but it is most common for the entire configuration to be defined in the httpd.conf file. Placing the entire configuration in httpd.conf is the recommended approach, it is the approach used on our sample Red Hat system, and it is the one we use in this tutorial. In the following sections, we examine the httpd.conf file in detail.
The httpd.conf file is an ASCII text file. Comments begin with a #, and the file is well-documented by comments. Most of the commands in the files are written in the form of a directive, followed by the value being assigned by the directive.
In addition to basic directives, the httpd.conf file includes containers that limit the scope of the directives they contain. For example, to limit certain directives to a specific directory, create a Directory container for those directives. Five different types of containers found in the Red Hat httpd.conf are:
<Directory pathname> The Directory directive creates a container for directives that apply to the directory identified by pathname. Any configuration directives that occur after the Directory directive and before the next </Directory> statement apply only to the specified directory.
<Files filename> The Files directive creates a container for directives that apply to the file identified by filename. Any configuration directives that occur after the Files directive and before the next </Files> statement apply only to the specified file. filename can refer to more than one file because it can contain the wildcard characters * and ?. Additionally, if the Files directive is followed by an optional ~ (tilde), the filename field is interpreted as a regular expression.
<Location document> The Location directive creates a container for directives that apply to a specific document. Any configuration directives that occur after the Location directive and before the next </Location> statement apply only to the specified document.
<IfDefine argument> The IfDefine directive creates a container for directives that are applied to the configuration only if the specified argument exists on the httpd command line. For example, the line <IfDefine HAVE_SSL> marks the beginning of a container of directives that are used only if the string -DHAVE_SSL occurs on the httpd command line. The IfDefine container ends with the next </IfDefine> statement.
<IfModule module> The IfModule directive creates a container for directives that are applied to the configuration only if the specified module is loaded. For example, the directives enclosed by <IfModule mod_userdir.c> and <\IfModule> are used only if the module mod_userdir is loaded.
Directories and files are easy to understand: They are parts of the filesystem that every system administrator knows. Documents, on the other hand, are specific to the web server. The screenful of information that appears in response to a web query is a document. It can be made up of many files from different directories. The Location container provides an easy way to refer to a complex document as a single entity. (We will see examples of Directory and Files containers later in this tutorial.)
The Red Hat configuration contains many IfDefine and IfModule statements. The IfModule statements enclose commands that depend on the specific module; they allow the configuration to load without a syntax error, even if a specific module is not loaded. The IfDefine statements allow optional Apache features to be selected from the command line. The /etc/init.d/httpd script that starts httpd on a Red Hat system creates an argument for every module found in /usr/lib/ apache. Therefore, the default behavior on a Red Hat system is to attempt to use every optional feature included in /usr/lib/apache.
The Red Hat Linux httpd.conf file is more than 1400 lines long. But most of the contents of the file is information from the Apache developers that is designed to help you understand how to configure Apache. The file is full of comments that explain the purpose of the configuration directives, and additional information about the directives is available in the online documentation at http://www.apache.org/. Still, the Red Hat httpd.conf file contains more than 250 active configuration lines. To tackle that much information, we have organized the discussion of the configuration file into related topics. This is not the way the directives are organized inside the configuration file. The configuration file organizes directives by scope: global environment directives, main server directives, and virtual host directives. (Virtual hosts are explained later.) That organization is great for httpd when it is processing the file, but not so great for a human reading the file. We bring directives together into related groups to make the individual directives more understandable because after you understand the individual directives, you will understand the entire configuration. We start our look at the httpd.conf file with the directives that load dynamically loadable modules. These modules must be loaded before the directives they provide can be used in the configuration, so it makes sense to discuss loading the modules before we discuss using the features they provide. Understanding dynamic loadable modules is a good place to start understanding Apache configuration.
In this tutorial:
- Apache Web Server
- Installing Apache
- Running httpd
- Configuring the Apache Server
- The httpd.conf File
- Loading Dynamic Shared Objects
- Basic Server Directives
- Multi-Homed Server Configuration
- Defining Where Things Are Stored
- Creating a Fancy Index
- Defining File Types
- Managing Child Processes
- Performance Tuning Directives
- Caching Directives
- Defining Virtual Hosts
- Web Server Security
- The CGI and SSI Threat
- Server Options for Documents and Directories
- Directory-Level Configuration Controls
- Defining Access Controls
- Requiring User Authentication
- High-Performance User Authentication
- Configuring SSL
- Managing Your Web Server
- Monitoring Your Server
- Apache Logging
- Defining Log Formats
- Using Conditional Logging