Apache ( httpd.conf ) Directives That A Web Server Admin Should Know

Apache Web Server Directives

Apache web server is the most popular web server designed for unix like operating system. It has become the dominating one over the other web servers because of its high flexibility and performance. Apache functionality can be extended with the help of compiled modules. Apache directives can be defined as the instruction to the web server on how to run. Apache configuration file is ‘httpd.conf’.

In this article, we will go through the important directives that an administrator should know for configuring apache and for performance tuning. These directives can be divided into three sections.

Section 1: Global Environment

The directives in this section affect the overall operation of Apache, such as the number of concurrent requests it can handle.

Sample Segment

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequestsPerChild 1000

a. Timeout

Amount of time the server will wait for certain events before failing a request. The default value is 300. Reducing this value to a very low number may cause a long running script to terminate earlier than expected. Also, it should not be set to too high for better performance.

b. KeepAlive

This defines whether the server allows more than one request per connection. Default value is “On”. When this directive is set to “on”, the client is allowed to serve multiple resources over the same connection. This will be very useful while serving web sites that have multiple images and you will see that the web page has been served so fast. But for high volume or load balanced servers, this should be set to ‘off’ for high connection throughput .

c. MaxKeepAliveRequests

This directive limits the number of requests allowed per connection while “KeepAlive” is “On”. Default value is 100.

d. KeepAliveTimeout

This refers to the number of seconds Apache will wait for a subsequent request before closing the connection. Default value is 15 seconds. For heavily loaded servers, this value may need to be reduced; otherwise child may sit idle waiting for new request on a connection that may not arrive which in turn increase the memory usage.

e. MinSpareServers

This defines the minimum number of idle child server processes. An idle process is one which is not handling a request. If there are fewer than ‘MinSpareServers’ idle, then the parent process creates new children at a maximum rate of 1 per second. Default value is 5. Setting the value to a higher value is always a bad idea as the memory will be used up for nothing.

f. MaxSpareServers

It sets the desired maximum number of idle child server processes. An idle process is one which is not handling a request. If there are more than MaxSpareServers idle, then the parent process will kill off the excess processes. It is better to set this value as double as ‘MinSpareServers’. If

you set it to equal or lesser than the ‘MinSpareServers’ value, Apache will automatically adjust it to MinSpareServers + 1.

g. StartServers

It sets the number of child server processes created on startup. It usually set to the same as ‘MinSpareServers’ value. Default is 5 for prefork MPM and 3 for worker MPM.

h. MaxClients

It sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will normally be queued. Once a child process is freed at the end of a different request, the connection will then be serviced. Default is 256. Setting this limit to a high value will result in using up of whole memory and cause high swap usage. The limit can be found by diving the ‘amount of memory reserved for Apache’ by ‘Average size of a single Apache process (usually between 15M to 20M).

i. MaxRequestsPerChild

It sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChild requests, the child process will die. This should not be too low or too high. If it is set to too high, it will increase the risk of memory leaks. So, the child processes should be killed after serving reasonable amount of requests. When a client uses a Keep-Alive connection it will be counted as a single "request" for the MaxRequestsPerChild directive, regardless of how many requests are sent using the connection.

j. LoadModule

This is used to load a module which was built as a DSO, so the directives contained in it are actually available before they are used.


LoadModule foo_module libexec/mod_foo.so

Section 2: Main Server Configuration

In this section, we will see the directives used by the 'main' server, which responds to any requests that aren't handled by adefinition. If these directives are available inside thedirective, default settings will be overridden for the virtual host being defined.

a. Listen

The Listen directive tells the server to accept incoming requests on the specified port or address-and-port combination. If only a port number is specified, the server listens to the given port on all interfaces. If an IP address is given as well as a port, the server will listen on the given port and interface.

Multiple Listen directives may be used to specify a number of addresses and ports to listen to. The server will respond to requests from any of the listed addresses and ports. Multiple Listen directives for the same ip address and port will result in an “Address already in use” error message.

Listen 80

b. <Directory>

This is called a sectional directive as it encloses a group of directives that applies to the specified directory.


<Directory "/var/www/htdocs">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

We can now go through the directives included above.

1. Options

Options allows you to define specific options to be available for a defined directory. Now, you can use ‘+’ to tell Apache to add the option or ‘-’ to remove an option. This directive can take any of the following or in combinations,

a. All : All options other than “MultiViews”

b. None

c. Includes : for enabling SSI (Server Side Includes)

d. Indexes : If a URL which maps to a directory is requested, and there is no DirectoryIndex (e.g., index.html) in that directory, then mod_autoindex will return a formatted listing of the directory.

e. FollowSymLinks : The server will follow symbolic links in this directory. This is the default setting.

f. ExecCGI : Execution of CGI scripts using mod_cgi is permitted.

g. Multiviews : Support for multilanguage pages

2. AllowOverride

This defines the directives that are allowed in .htaccess files. The value ‘None’ will disable the .htaccess usage and “All” will allow all directives. You can specifically mention the directive types too.

3. Allow, Deny Directives

These directives will help to restrict access to the particular directory. You can mention the IP address or Hostname which need to be granted/denied access.

Section 3 : Virtual Hosts


This sectional directive contains directives that apply only to a specific hostname or IP address.


ServerAdmin webmaster@host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log

We can now check the enclosed directives.

a. ServerAdmin : It sets the e-mail address that the server includes in any error messages it returns to the client.

b. DocumentRoot : This directive sets the directory from which httpd will serve files. Unless matched by a directive like ‘Alias’, the server appends the path from the requested URL to the document root to make the path to the document.
That is,
DocumentRoot /usr/web
Then, access to http://www.my.host.com/index.html refers to /usr/web/index.html.

c. ServerName: Hostname and port that the server uses to identify itself.

d. ErrorLog: The ErrorLog directive sets the name of the file to which the server will log any errors it encounters. If the file-path is not absolute then it is assumed to be relative to the ‘ServerRoot’.

These are the main directives that help apache administrators to configure it properly.

About Leena

Leena has been working on Linux operating systems and open source technologies for past 6 years. She loves to read and write on Linux related technologies and is a big fan of open source software's.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.