Product SiteDocumentation Site

11.3. Editing the Configuration Files

When the httpd service is started, by default, it reads the configuration from locations that are listed in Table 11.1, “The httpd service configuration files”.
Table 11.1. The httpd service configuration files
Path Description
/etc/httpd/conf/httpd.conf The main configuration file.
/etc/httpd/conf.d/ An auxiliary directory for configuration files that are included in the main configuration file.

Although the default configuration should be suitable for most situations, it is a good idea to become at least familiar with some of the more important configuration options. Note that for any changes to take effect, the web server has to be restarted first. Refer to Section 11.2.3, “Restarting the Service” for more information on how to restart the httpd service.
To check the configuration for possible errors, type the following at a shell prompt:
~]# service httpd configtest
Syntax OK
To make the recovery from mistakes easier, it is recommended that you make a copy of the original file before editing it.

11.3.1. Common httpd.conf Directives

The following directives are commonly used in the /etc/httpd/conf/httpd.conf configuration file:
<Directory>
The <Directory> directive allows you to apply certain directives to a particular directory only. It takes the following form:
<Directory directory>
  directive
  …
</Directory>
The directory can be either a full path to an existing directory in the local file system, or a wildcard expression.
This directive can be used to configure additional cgi-bin directories for server-side scripts located outside the directory that is specified by ScriptAlias. In this case, the ExecCGI and AddHandler directives must be supplied, and the permissions on the target directory must be set correctly (that is, 0755).
Example 11.1. Using the <Directory> directive
<Directory /var/www/html>
  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

<IfDefine>
The IfDefine directive allows you to use certain directives only when a particular parameter is supplied on the command line. It takes the following form:
<IfDefine [!]parameter>
  directive
  …
</IfDefine>
The parameter can be supplied at a shell prompt using the -Dparameter command line option (for example, httpd -DEnableHome). If the optional exclamation mark (that is, !) is present, the enclosed directives are used only when the parameter is not specified.
Example 11.2. Using the <IfDefine> directive
<IfDefine EnableHome>
  UserDir public_html
</IfDefine>

<IfModule>
The <IfModule> directive allows you to use certain directive only when a particular module is loaded. It takes the following form:
<IfModule [!]module>
  directive
  …
</IfModule>
The module can be identified either by its name, or by the filename. If the optional exclamation mark (that is, !) is present, the enclosed directives are used only when the module is not loaded.
Example 11.3. Using the <IfModule> directive
<IfModule mod_disk_cache.c>
  CacheEnable disk /
  CacheRoot /var/cache/mod_proxy
</IfModule>

<Location>
The <Location> directive allows you to apply certain directives to a particular URL only. It takes the following form:
<Location url>
  directive
  …
</Location>
The url can be either a path relative to the directory specified by the DocumentRoot directive (for example, /server-info), or an external URL such as http://example.com/server-info.
Example 11.4. Using the <Location> directive
<Location /server-info>
  SetHandler server-info
  Order deny,allow
  Deny from all
  Allow from .example.com
</Location>

<Proxy>
The <Proxy> directive allows you to apply certain directives to the proxy server only. It takes the following form:
<Proxy pattern>
  directive
  …
</Proxy>
The pattern can be an external URL, or a wildcard expression (for example, http://example.com/*).
Example 11.5. Using the <Proxy> directive
<Proxy *>
  Order deny,allow
  Deny from all
  Allow from .example.com
</Proxy>

<VirtualHost>
The <VirtualHost> directive allows you apply certain directives to particular virtual hosts only. It takes the following form:
<VirtualHost address[:port]…>
  directive
  …
</VirtualHost>
The address can be an IP address, a fully qualified domain name, or a special form as described in Table 11.2, “Available <VirtualHost> options”.
Table 11.2. Available <VirtualHost> options
Option Description
* Represents all IP addresses.
_default_ Represents unmatched IP addresses.

Example 11.6. Using the <VirtualHost> directive
<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot /www/docs/penguin.example.com
  ServerName penguin.example.com
  ErrorLog logs/penguin.example.com-error_log
  CustomLog logs/penguin.example.com-access_log common
</VirtualHost>

AccessFileName
The AccessFileName directive allows you to specify the file to be used to customize access control information for each directory. It takes the following form:
AccessFileName filename
The filename is a name of the file to look for in the requested directory. By default, the server looks for .htaccess.
For security reasons, the directive is typically followed by the Files tag to prevent the files beginning with .ht from being accessed by web clients. This includes the .htaccess and .htpasswd files.
Example 11.7. Using the AccessFileName directive
AccessFileName .htaccess

<Files ~ "^\.ht">
  Order allow,deny
  Deny from all
  Satisfy All
</Files>

Action
The Action directive allows you to specify a CGI script to be executed when a certain media type is requested. It takes the following form:
Action content-type path
The content-type has to be a valid MIME type such as text/html, image/png, or application/pdf. The path refers to an existing CGI script, and must be relative to the directory specified by the DocumentRoot directive (for example, /cgi-bin/process-image.cgi).
Example 11.8. Using the Action directive
Action image/png /cgi-bin/process-image.cgi

AddDescription
The AddDescription directive allows you to specify a short description to be displayed in server-generated directory listings for a given file. It takes the following form:
AddDescription "description" filename
The description should be a short text enclosed in double quotes (that is, "). The filename can be a full filename, a file extension, or a wildcard expression.
Example 11.9. Using the AddDescription directive
AddDescription "GZIP compressed tar archive" .tgz

AddEncoding
The AddEncoding directive allows you to specify an encoding type for a particular file extension. It takes the following form:
AddEncoding encoding extension
The encoding has to be a valid MIME encoding such as x-compress, x-gzip, etc. The extension is a case sensitive file extension, and is conventionally written with a leading dot (for example, .gz).
This directive is typically used to instruct web browsers to uncompress certain file types as they are downloaded.
Example 11.10. Using the AddEncoding directive
AddEncoding x-gzip .gz .tgz

AddHandler
The AddHandler directive allows you to map certain file extensions to a selected handler. It takes the following form:
AddHandler handler extension
The handler has to be a name of previously defined handler. The extension is a case sensitive file extension, and is conventionally written with a leading dot (for example, .cgi).
This directive is typically used to treat files with the .cgi extension as CGI scripts regardless of the directory they are in. Additionally, it is also commonly used to process server-parsed HTML and image-map files.
Example 11.11. Using the AddHandler option
AddHandler cgi-script .cgi

AddIcon
The AddIcon directive allows you to specify an icon to be displayed for a particular file in server-generated directory listings. It takes the following form:
AddIcon path pattern
The path refers to an existing icon file, and must be relative to the directory specified by the DocumentRoot directive (for example, /icons/folder.png). The pattern can be a filename, a file extension, a wildcard expression, or a special form as described in the following table:
Table 11.3. Available AddIcon options
Option Description
^^DIRECTORY^^ Represents a directory.
^^BLANKICON^^ Represents a blank line.

Example 11.12. Using the AddIcon directive
AddIcon /icons/text.png .txt README

AddIconByEncoding
The AddIconByEncoding directive allows you to specify an icon to be displayed for a particular encoding type in server-generated directory listings. It takes the following form:
AddIconByEncoding path encoding
The path refers to an existing icon file, and must be relative to the directory specified by the DocumentRoot directive (for example, /icons/compressed.png). The encoding has to be a valid MIME encoding such as x-compress, x-gzip, etc.
Example 11.13. Using the AddIconByEncoding directive
AddIconByEncoding /icons/compressed.png x-compress x-gzip

AddIconByType
The AddIconByType directive allows you to specify an icon to be displayed for a particular media type in server-generated directory listings. It takes the following form:
AddIconByType path content-type
The path refers to an existing icon file, and must be relative to the directory specified by the DocumentRoot directive (for example, /icons/text.png). The content-type has to be either a valid MIME type (for example, text/html or image/png), or a wildcard expression such as text/*, image/*, etc.
Example 11.14. Using the AddIconByType directive
AddIconByType /icons/video.png video/*

AddLanguage
The AddLanguage directive allows you to associate a file extension with a specific language. It takes the following form:
AddLanguage language extension
The language has to be a valid MIME language such as cs, en, or fr. The extension is a case sensitive file extension, and is conventionally written with a leading dot (for example, .cs).
This directive is especially useful for web servers that serve content in multiple languages based on the client's language settings.
Example 11.15. Using the AddLanguage directive
AddLanguage cs .cs .cz

AddType
The AddType directive allows you to define or override the media type for a particular file extension. It takes the following form:
AddType content-type extension
The content-type has to be a valid MIME type such as text/html, image/png, etc. The extension is a case sensitive file extension, and is conventionally written with a leading dot (for example, .cs).
Example 11.16. Using the AddType directive
AddType application/x-gzip .gz .tgz

Alias
The Alias directive allows you to refer to files and directories outside the default directory specified by the DocumentRoot directive. It takes the following form:
Alias url-path real-path
The url-path must be relative to the directory specified by the DocumentRoot directive (for example, /images/). The real-path is a full path to a file or directory in the local file system.
This directive is typically followed by the Directory tag with additional permissions to access the target directory. By default, the /icons/ alias is created so that the icons from /var/www/icons/ are displayed in server-generated directory listings.
Example 11.17. Using the Alias directive
Alias /icons/ /var/www/icons/

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

Allow
The Allow directive allows you to specify which clients have permission to access a given directory. It takes the following form:
Allow from client
The client can be a domain name, an IP address (both full and partial), a network/netmask pair, or all for all clients.
Example 11.18. Using the Allow directive
Allow from 192.168.1.0/255.255.255.0

AllowOverride
The AllowOverride directive allows you to specify which directives in a .htaccess file can override the default configuration. It takes the following form:
AllowOverride type
The type has to be one of the available grouping options as described in Table 11.4, “Available AllowOverride options”.
Table 11.4. Available AllowOverride options
Option Description
All All directives in .htaccess are allowed to override earlier configuration settings.
None No directive in .htaccess is allowed to override earlier configuration settings.
AuthConfig Allows the use of authorization directives such as AuthName, AuthType, or Require.
FileInfo Allows the use of file type, metadata, and mod_rewrite directives such as DefaultType, RequestHeader, or RewriteEngine, as well as the Action directive.
Indexes Allows the use of directory indexing directives such as AddDescription, AddIcon, or FancyIndexing.
Limit Allows the use of host access directives, that is, Allow, Deny, and Order.
Options[=option,…] Allows the use of the Options directive. Additionally, you can provide a comma-separated list of options to customize which options can be set using this directive.

Example 11.19. Using the AllowOverride directive
AllowOverride FileInfo AuthConfig Limit

BrowserMatch
The BrowserMatch directive allows you to modify the server behavior based on the client's web browser type. It takes the following form:
BrowserMatch pattern variable
The pattern is a regular expression to match the User-Agent HTTP header field. The variable is an environment variable that is set when the header field matches the pattern.
By default, this directive is used to deny connections to specific browsers with known issues, and to disable keepalives and HTTP header flushes for browsers that are known to have problems with these actions.
Example 11.20. Using the BrowserMatch directive
BrowserMatch "Mozilla/2" nokeepalive

CacheDefaultExpire
The CacheDefaultExpire option allows you to set how long to cache a document that does not have any expiration date or the date of its last modification specified. It takes the following form:
CacheDefaultExpire time
The time specified in seconds. The default option is 3600 (that is, one hour).
Example 11.21. Using the CacheDefaultExpire directive
CacheDefaultExpire 3600

CacheDisable
The CacheDisable directive allows you to disable caching of certain URLs. It takes the following form:
CacheDisable path
The path must be relative to the directory specified by the DocumentRoot directive (for example, /files/).
Example 11.22. Using the CacheDisable directive
CacheDisable /temporary

CacheEnable
The CacheEnable directive allows you to specify a cache type to be used for certain URLs. It takes the following form:
CacheEnable type url
The type has to be a valid cache type as described in Table 11.5, “Available cache types”. The url can be a path relative to the directory specified by the DocumentRoot directive (for example, /images/), a protocol (for example, ftp://), or an external URL such as http://example.com/.
Table 11.5. Available cache types
Type Description
mem The memory-based storage manager.
disk The disk-based storage manager.
fd The file descriptor cache.

Example 11.23. Using the CacheEnable directive
CacheEnable disk /

CacheLastModifiedFactor
The CacheLastModifiedFactor directive allows you to customize how long to cache a document that does not have any expiration date specified, but that provides information about the date of its last modification. It takes the following form:
CacheLastModifiedFactor number
The number is a coefficient to be used to multiply the time that passed since the last modification of the document. The default option is 0.1 (that is, one tenth).
Example 11.24. Using the CacheLastModifiedFactor directive
CacheLastModifiedFactor 0.1

CacheMaxExpire
The CacheMaxExpire directive allows you to specify the maximum amount of time to cache a document. It takes the following form:
CacheMaxExpire time
The time is specified in seconds. The default option is 86400 (that is, one day).
Example 11.25. Using the CacheMaxExpire directive
CacheMaxExpire 86400

CacheNegotiatedDocs
The CacheNegotiatedDocs directive allows you to enable caching of the documents that were negotiated on the basis of content. It takes the following form:
CacheNegotiatedDocs option
The option has to be a valid keyword as described in Table 11.6, “Available CacheNegotiatedDocs options”. Since the content-negotiated documents may change over time or because of the input from the requester, the default option is Off.
Table 11.6. Available CacheNegotiatedDocs options
Option Description
On Enables caching the content-negotiated documents.
Off Disables caching the content-negotiated documents.

Example 11.26. Using the CacheNegotiatedDocs directive
CacheNegotiatedDocs On

CacheRoot
The CacheRoot directive allows you to specify the directory to store cache files in. It takes the following form:
CacheRoot directory
The directory must be a full path to an existing directory in the local file system. The default option is /var/cache/mod_proxy/.
Example 11.27. Using the CacheRoot directive
CacheRoot /var/cache/mod_proxy

CustomLog
The CustomLog directive allows you to specify the log filename and the log file format. It takes the following form:
CustomLog path format
The path refers to a log file, and must be relative to the directory that is specified by the ServerRoot directive (that is, /etc/httpd/ by default). The format has to be either an explicit format string, or a format name that was previously defined using the LogFormat directive.
Example 11.28. Using the CustomLog directive
CustomLog logs/access_log combined

DefaultIcon
The DefaultIcon directive allows you to specify an icon to be displayed for a file in server-generated directory listings when no other icon is associated with it. It takes the following form:
DefaultIcon path
The path refers to an existing icon file, and must be relative to the directory specified by the DocumentRoot directive (for example, /icons/unknown.png).
Example 11.29. Using the DefaultIcon directive
DefaultIcon /icons/unknown.png

DefaultType
The DefaultType directive allows you to specify a media type to be used in case the proper MIME type cannot be determined by the server. It takes the following form:
DefaultType content-type
The content-type has to be a valid MIME type such as text/html, image/png, application/pdf, etc.
Example 11.30. Using the DefaultType directive
DefaultType text/plain

Deny
The Deny directive allows you to specify which clients are denied access to a given directory. It takes the following form:
Deny from client
The client can be a domain name, an IP address (both full and partial), a network/netmask pair, or all for all clients.
Example 11.31. Using the Deny directive
Deny from 192.168.1.1

DirectoryIndex
The DirectoryIndex directive allows you to specify a document to be served to a client when a directory is requested (that is, when the URL ends with the / character). It takes the following form:
DirectoryIndex filename
The filename is a name of the file to look for in the requested directory. By default, the server looks for index.html, and index.html.var.
Example 11.32. Using the DirectoryIndex directive
DirectoryIndex index.html index.html.var

DocumentRoot
The DocumentRoot directive allows you to specify the main directory from which the content is served. It takes the following form:
DocumentRoot directory
The directory must be a full path to an existing directory in the local file system. The default option is /var/www/html/.
Example 11.33. Using the DocumentRoot directive
DocumentRoot /var/www/html

ErrorDocument
The ErrorDocument directive allows you to specify a document or a message to be displayed as a response to a particular error. It takes the following form:
ErrorDocument error-code action
The error-code has to be a valid code such as 403 (Forbidden), 404 (Not Found), or 500 (Internal Server Error). The action can be either a URL (both local and external), or a message string enclosed in double quotes (that is, ").
Example 11.34. Using the ErrorDocument directive
ErrorDocument 403 "Access Denied"
ErrorDocument 404 /404-not_found.html

ErrorLog
The ErrorLog directive allows you to specify a file to which the server errors are logged. It takes the following form:
ErrorLog path
The path refers to a log file, and can be either absolute, or relative to the directory that is specified by the ServerRoot directive (that is, /etc/httpd/ by default). The default option is logs/error_log
Example 11.35. Using the ErrorLog directive
ErrorLog logs/error_log

ExtendedStatus
The ExtendedStatus directive allows you to enable detailed server status information. It takes the following form:
ExtendedStatus option
The option has to be a valid keyword as described in Table 11.7, “Available ExtendedStatus options”. The default option is Off.
Table 11.7. Available ExtendedStatus options
Option Description
On Enables generating the detailed server status.
Off Disables generating the detailed server status.

Example 11.36. Using the ExtendedStatus directive
ExtendedStatus On

Group
The Group directive allows you to specify the group under which the httpd service will run. It takes the following form:
Group group
The group has to be an existing UNIX group. The default option is apache.
Note that Group is no longer supported inside <VirtualHost>, and has been replaced by the SuexecUserGroup directive.
Example 11.37. Using the Group directive
Group apache

HeaderName
The HeaderName directive allows you to specify a file to be prepended to the beginning of the server-generated directory listing. It takes the following form:
HeaderName filename
The filename is a name of the file to look for in the requested directory. By default, the server looks for HEADER.html.
Example 11.38. Using the HeaderName directive
HeaderName HEADER.html

HostnameLookups
The HostnameLookups directive allows you to enable automatic resolving of IP addresses. It takes the following form:
HostnameLookups option
The option has to be a valid keyword as described in Table 11.8, “Available HostnameLookups options”. To conserve resources on the server, the default option is Off.
Table 11.8. Available HostnameLookups options
Option Description
On Enables resolving the IP address for each connection so that the hostname can be logged. However, this also adds a significant processing overhead.
Double Enables performing the double-reverse DNS lookup. In comparison to the above option, this adds even more processing overhead.
Off Disables resolving the IP address for each connection.

Note that when the presence of hostnames is required in server log files, it is often possible to use one of the many log analyzer tools that perform the DNS lookups more efficiently.
Example 11.39. Using the HostnameLookups directive
HostnameLookups Off

Include
The Include directive allows you to include other configuration files. It takes the following form:
Include filename
The filename can be an absolute path, a path relative to the directory specified by the ServerRoot directive, or a wildcard expression. All configuration files from the /etc/httpd/conf.d/ directory are loaded by default.
Example 11.40. Using the Include directive
Include conf.d/*.conf

IndexIgnore
The IndexIgnore directive allows you to specify a list of filenames to be omitted from the server-generated directory listings. It takes the following form:
IndexIgnore filename
The filename option can be either a full filename, or a wildcard expression.
Example 11.41. Using the IndexIgnore directive
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

IndexOptions
The IndexOptions directive allows you to customize the behavior of server-generated directory listings. It takes the following form:
IndexOptions option
The option has to be a valid keyword as described in Table 11.9, “Available directory listing options”. The default options are Charset=UTF-8, FancyIndexing, HTMLTable, NameWidth=*, and VersionSort.
Table 11.9. Available directory listing options
Option Description
Charset=encoding Specifies the character set of a generated web page. The encoding has to be a valid character set such as UTF-8 or ISO-8859-2.
Type=content-type Specifies the media type of a generated web page. The content-type has to be a valid MIME type such as text/html or text/plain.
DescriptionWidth=value Specifies the width of the description column. The value can be either a number of characters, or an asterisk (that is, *) to adjust the width automatically.
FancyIndexing Enables advanced features such as different icons for certain files or possibility to re-sort a directory listing by clicking on a column header.
FolderFirst Enables listing directories first, always placing them above files.
HTMLTable Enables the use of HTML tables for directory listings.
IconsAreLinks Enables using the icons as links.
IconHeight=value Specifies an icon height. The value is a number of pixels.
IconWidth=value Specifies an icon width. The value is a number of pixels.
IgnoreCase Enables sorting files and directories in a case-sensitive manner.
IgnoreClient Disables accepting query variables from a client.
NameWidth=value Specifies the width of the filename column. The value can be either a number of characters, or an asterisk (that is, *) to adjust the width automatically.
ScanHTMLTitles Enables parsing the file for a description (that is, the title element) in case it is not provided by the AddDescription directive.
ShowForbidden Enables listing the files with otherwise restricted access.
SuppressColumnSorting Disables re-sorting a directory listing by clicking on a column header.
SuppressDescription Disables reserving a space for file descriptions.
SuppressHTMLPreamble Disables the use of standard HTML preamble when a file specified by the HeaderName directive is present.
SuppressIcon Disables the use of icons in directory listings.
SuppressLastModified Disables displaying the date of the last modification field in directory listings.
SuppressRules Disables the use of horizontal lines in directory listings.
SuppressSize Disables displaying the file size field in directory listings.
TrackModified Enables returning the Last-Modified and ETag values in the HTTP header.
VersionSort Enables sorting files that contain a version number in the expected manner.
XHTML Enables the use of XHTML 1.0 instead of the default HTML 3.2.

Example 11.42. Using the IndexOptions directive
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8

KeepAlive
The KeepAlive directive allows you to enable persistent connections. It takes the following form:
KeepAlive option
The option has to be a valid keyword as described in Table 11.10, “Available KeepAlive options”. The default option is Off.
Table 11.10. Available KeepAlive options
Option Description
On Enables the persistent connections. In this case, the server will accept more than one request per connection.
Off Disables the keep-alive connections.

Note that when the persistent connections are enabled, on a busy server, the number of child processes can increase rapidly and eventually reach the maximum limit, slowing down the server significantly. To reduce the risk, it is recommended that you set KeepAliveTimeout to a low number, and monitor the /var/log/httpd/logs/error_log log file carefully.
Example 11.43. Using the KeepAlive directive
KeepAlive Off

KeepAliveTimeout
The KeepAliveTimeout directive allows you to specify the amount of time to wait for another request before closing the connection. It takes the following form:
KeepAliveTimeout time
The time is specified in seconds. The default option is 15.
Example 11.44. Using the KeepAliveTimeout directive
KeepAliveTimeout 15

LanguagePriority
The LanguagePriority directive allows you to customize the precedence of languages. It takes the following form:
LanguagePriority language
The language has to be a valide MIME language such as cs, en, or fr.
This directive is especially useful for web servers that serve content in multiple languages based on the client's language settings.
Example 11.45. Using the LanguagePriority directive
LanguagePriority sk cs en

Listen
The Listen directive allows you to specify IP addresses or ports to listen to. It takes the following form:
Listen [ip-address:]port [protocol]
The ip-address is optional and unless supplied, the server will accept incoming requests on a given port from all IP addresses. Since the protocol is determined automatically from the port number, it can be usually omitted. The default option is to listen to port 80.
Note that if the server is configured to listen to a port under 1024, only superuser will be able to start the httpd service.
Example 11.46. Using the Listen directive
Listen 80

LoadModule
The LoadModule directive allows you to load a Dynamic Shared Object (DSO) module. It takes the following form:
LoadModule name path
The name has to be a valid identifier of the required module. The path refers to an existing module file, and must be relative to the directory in which the libraries are placed (that is, /usr/lib/httpd/ on 32-bit and /usr/lib64/httpd/ on 64-bit systems by default).
Refer to Section 11.4, “Working with Modules” for more information on the Apache HTTP Server's DSO support.
Example 11.47. Using the LoadModule directive
LoadModule php5_module modules/libphp5.so

LogFormat
The LogFormat directive allows you to specify a log file format. It takes the following form:
LogFormat format name
The format is a string consisting of options as described in Table 11.11, “Common LogFormat options”. The name can be used instead of the format string in the CustomLog directive.
Table 11.11. Common LogFormat options
Option Description
%b Represents the size of the response in bytes.
%h Represents the IP address or hostname of a remote client.
%l Represents the remote log name if supplied. If not, a hyphen (that is, -) is used instead.
%r Represents the first line of the request string as it came from the browser or client.
%s Represents the status code.
%t Represents the date and time of the request.
%u If the authentication is required, it represents the remote user. If not, a hyphen (that is, -) is used instead.
%{field} Represents the content of the HTTP header field. The common options include %{Referer} (the URL of the web page that referred the client to the server) and %{User-Agent} (the type of the web browser making the request).

Example 11.48. Using the LogFormat directive
LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogLevel
The LogLevel directive allows you to customize the verbosity level of the error log. It takes the following form:
LogLevel option
The option has to be a valid keyword as described in Table 11.12, “Available LogLevel options”. The default option is warn.
Table 11.12. Available LogLevel options
Option Description
emerg Only the emergency situations when the server cannot perform its work are logged.
alert All situations when an immediate action is required are logged.
crit All critical conditions are logged.
error All error messages are logged.
warn All warning messages are logged.
notice Even normal, but still significant situations are logged.
info Various informational messages are logged.
debug Various debugging messages are logged.

Example 11.49. Using the LogLevel directive
LogLevel warn

MaxKeepAliveRequests
The MaxKeepAliveRequests directive allows you to specify the maximum number of requests for a persistent connection. It takes the following form:
MaxKeepAliveRequests number
A high number can improve the performance of the server. Note that using 0 allows unlimited number of requests. The default option is 100.
Example 11.50. Using the MaxKeepAliveRequests option
MaxKeepAliveRequests 100

NameVirtualHost
The NameVirtualHost directive allows you to specify the IP address and port number for a name-based virtual host. It takes the following form:
NameVirtualHost ip-address[:port]
The ip-address can be either a full IP address, or an asterisk (that is, *) representing all interfaces. Note that IPv6 addresses have to be enclosed in square brackets (that is, [ and ]). The port is optional.
Name-based virtual hosting allows one Apache HTTP Server to serve different domains without using multiple IP addresses.

Important: Using Secure HTTP Connections

Name-based virtual hosts only work with non-secure HTTP connections. If using virtual hosts with a secure server, use IP address-based virtual hosts instead.
Example 11.51. Using the NameVirtualHost directive
NameVirtualHost *:80

Options
The Options directive allows you to specify which server features are available in a particular directory. It takes the following form:
Options option
The option has to be a valid keyword as described in Table 11.13, “Available server features”.
Table 11.13. Available server features
Option Description
ExecCGI Enables the execution of CGI scripts.
FollowSymLinks Enables following symbolic links in the directory.
Includes Enables server-side includes.
IncludesNOEXEC Enables server-side includes, but does not allow the execution of commands.
Indexes Enables server-generated directory listings.
MultiViews Enables content-negotiated MultiViews.
SymLinksIfOwnerMatch Enables following symbolic links in the directory when both the link and the target file have the same owner.
All Enables all of the features above with the exception of MultiViews.
None Disables all of the features above.

Example 11.52. Using the Options directive
Options Indexes FollowSymLinks

Order
The Order directive allows you to specify the order in which the Allow and Deny directives are evaluated. It takes the following form:
Order option
The option has to be a valid keyword as described in Table 11.14, “Available Order options”. The default option is allow,deny.
Table 11.14. Available Order options
Option Description
allow,deny Allow directives are evaluated first.
deny,allow Deny directives are evaluated first.

Example 11.53. Using the Order directive
Order allow,deny

PidFile
The PidFile directive allows you to specify a file to which the process ID (PID) of the server is stored. It takes the following form:
PidFile path
The path refers to a pid file, and can be either absolute, or relative to the directory that is specified by the ServerRoot directive (that is, /etc/httpd/ by default). The default option is run/httpd.pid.
Example 11.54. Using the PidFile directive
PidFile run/httpd.pid

ProxyRequests
The ProxyRequests directive allows you to enable forward proxy requests. It takes the following form:
ProxyRequests option
The option has to be a valid keyword as described in Table 11.15, “Available ProxyRequests options”. The default option is Off.
Table 11.15. Available ProxyRequests options
Option Description
On Enables forward proxy requests.
Off Disables forward proxy requests.

Example 11.55. Using the ProxyRequests directive
ProxyRequests On

ReadmeName
The ReadmeName directive allows you to specify a file to be appended to the end of the server-generated directory listing. It takes the following form:
ReadmeName filename
The filename is a name of the file to look for in the requested directory. By default, the server looks for README.html.
Example 11.56. Using the ReadmeName directive
ReadmeName README.html

Redirect
The Redirect directive allows you to redirect a client to another URL. It takes the following form:
Redirect [status] path url
The status is optional, and if provided, it has to be a valid keyword as described in Table 11.16, “Available status options”. The path refers to the old location, and must be relative to the directory specified by the DocumentRoot directive (for example, /docs). The url refers to the current location of the content (for example, http://docs.example.com).
Table 11.16. Available status options
Status Description
permanent Indicates that the requested resource has been moved permanently. The 301 (Moved Permanently) status code is returned to a client.
temp Indicates that the requested resource has been moved only temporarily. The 302 (Found) status code is returned to a client.
seeother Indicates that the requested resource has been replaced. The 303 (See Other) status code is returned to a client.
gone Indicates that the requested resource has been removed permanently. The 410 (Gone) status is returned to a client.

Note that for more advanced redirection techniques, you can use the mod_rewrite module that is part of the Apache HTTP Server installation.
Example 11.57. Using the Redirect directive
Redirect permanent /docs http://docs.example.com

ScriptAlias
The ScriptAlias directive allows you to specify the location of CGI scripts. It takes the following form:
ScriptAlias url-path real-path
The url-path must be relative to the directory specified by the DocumentRoot directive (for example, /cgi-bin/). The real-path is a full path to a file or directory in the local file system.
This directive is typically followed by the Directory tag with additional permissions to access the target directory. By default, the /cgi-bin/ alias is created so that the scripts located in the /var/www/cgi-bin/ are accessible.
The ScriptAlias directive is used for security reasons to prevent CGI scripts from being viewed as ordinary text documents.
Example 11.58. Using the ScriptAlias directive
ScriptAlias /cgi-bin/ /var/www/cgi-bin/

<Directory "/var/www/cgi-bin">
  AllowOverride None
  Options None
  Order allow,deny
  Allow from all
</Directory>

ServerAdmin
The ServerAdmin directive allows you to specify the email address of the server administrator to be displayed in server-generated web pages. It takes the following form:
ServerAdmin email
The default option is root@localhost.
This directive is commonly set to webmaster@hostname, where hostname is the address of the server. Once set, alias webmaster to the person responsible for the web server in /etc/aliases, and as superuser, run the newaliases command.
Example 11.59. Using the ServerAdmin directive
ServerAdmin [email protected]

ServerName
The ServerName directive allows you to specify the hostname and the port number of a web server. It takes the following form:
ServerName hostname[:port]
The hostname has to be a fully qualified domain name (FQDN) of the server. The port is optional, but when supplied, it has to match the number specified by the Listen directive.
When using this directive, make sure that the IP address and server name pair are included in the /etc/hosts file.
Example 11.60. Using the ServerName directive
ServerName penguin.example.com:80

ServerRoot
The ServerRoot directive allows you to specify the directory in which the server operates. It takes the following form:
ServerRoot directory
The directory must be a full path to an existing directory in the local file system. The default option is /etc/httpd/.
Example 11.61. Using the ServerRoot directive
ServerRoot /etc/httpd

ServerSignature
The ServerSignature directive allows you to enable displaying information about the server on server-generated documents. It takes the following form:
ServerSignature option
The option has to be a valid keyword as described in Table 11.17, “Available ServerSignature options”. The default option is On.
Table 11.17. Available ServerSignature options
Option Description
On Enables appending the server name and version to server-generated pages.
Off Disables appending the server name and version to server-generated pages.
EMail Enables appending the server name, version, and the email address of the system administrator as specified by the ServerAdmin directive to server-generated pages.

Example 11.62. Using the ServerSignature directive
ServerSignature On

ServerTokens
The ServerTokens directive allows you to customize what information are included in the Server response header. It takes the following form:
ServerTokens option
The option has to be a valid keyword as described in Table 11.18, “Available ServerTokens options”. The default option is OS.
Table 11.18. Available ServerTokens options
Option Description
Prod Includes the product name only (that is, Apache).
Major Includes the product name and the major version of the server (for example, 2).
Minor Includes the product name and the minor version of the server (for example, 2.2).
Min Includes the product name and the minimal version of the server (for example, 2.2.15).
OS Includes the product name, the minimal version of the server, and the type of the operating system it is running on (for example, Red Hat).
Full Includes all the information above along with the list of loaded modules.

Note that for security reasons, it is recommended to reveal as little information about the server as possible.
Example 11.63. Using the ServerTokens directive
ServerTokens Prod

SuexecUserGroup
The SuexecUserGroup directive allows you to specify the user and group under which the CGI scripts will be run. It takes the following form:
SuexecUserGroup user group
The user has to be an existing user, and the group must be a valid UNIX group.
For security reasons, the CGI scripts should not be run with root privileges. Note that in <VirtualHost>, SuexecUserGroup replaces the User and Group directives.
Example 11.64. Using the SuexecUserGroup directive
SuexecUserGroup apache apache

Timeout
The Timeout directive allows you to specify the amount of time to wait for an event before closing a connection. It takes the following form:
Timeout time
The time is specified in seconds. The default option is 60.
Example 11.65. Using the Timeout directive
Timeout 60

TypesConfig
The TypesConfig allows you to specify the location of the MIME types configuration file. It takes the following form:
TypesConfig path
The path refers to an existing MIME types configuration file, and can be either absolute, or relative to the directory that is specified by the ServerRoot directive (that is, /etc/httpd/ by default). The default option is /etc/mime.types.
Note that instead of editing /etc/mime.types, the recommended way to add MIME type mapping to the Apache HTTP Server is to use the AddType directive.
Example 11.66. Using the TypesConfig directive
TypesConfig /etc/mime.types

UseCanonicalName
The UseCanonicalName allows you to specify the way the server refers to itself. It takes the following form:
UseCanonicalName option
The option has to be a valid keyword as described in Table 11.19, “Available UseCanonicalName options”. The default option is Off.
Table 11.19. Available UseCanonicalName options
Option Description
On Enables the use of the name that is specified by the ServerName directive.
Off Disables the use of the name that is specified by the ServerName directive. The hostname and port number provided by the requesting client are used instead.
DNS Disables the use of the name that is specified by the ServerName directive. The hostname determined by a reverse DNS lookup is used instead.

Example 11.67. Using the UseCanonicalName directive
UseCanonicalName Off

User
The User directive allows you to specify the user under which the httpd service will run. It takes the following form:
User user
The user has to be an existing UNIX user. The default option is apache.
For security reasons, the httpd service should not be run with root privileges. Note that User is no longer supported inside <VirtualHost>, and has been replaced by the SuexecUserGroup directive.
Example 11.68. Using the User directive
User apache

UserDir
The UserDir directive allows you to enable serving content from users' home directories. It takes the following form:
UserDir option
The option can be either a name of the directory to look for in user's home directory (typically public_html), or a valid keyword as described in Table 11.20, “Available UserDir options”. The default option is disabled.
Table 11.20. Available UserDir options
Option Description
enabled user Enables serving content from home directories of given users.
disabled [user] Disables serving content from home directories, either for all users, or, if a space separated list of users is supplied, for given users only.

Note: Set the Correct Permissions

In order for the web server to access the content, the permissions on relevant directories and files must be set correctly. Make sure that all users are able to access the home directories, and that they can access and read the content of the directory specified by the UserDir directive. For example:
~]# chmod a+x /home/username/
~]# chmod a+rx /home/username/public_html/
All files in this directory must be set accordingly.
Example 11.69. Using the UserDir directive
UserDir public_html