11.5.1. General Configuration Tips
Before editing httpd.conf
, make a copy the original file. Creating a backup makes it easier to recover from mistakes made while editing the configuration file.
If a mistake is made and the Web server does not work correctly, first review recently edited passages in httpd.conf
to verify there are no typos.
Next look in the Web server's error log, /var/log/httpd/error_log
. The error log may not be easy to interpret, depending on your level of expertise. However, the last entries in the error log should provide useful information.
The following subsections contain a list of short descriptions for many of the directives included in
httpd.conf
. These descriptions are not exhaustive. For more information, refer to the Apache documentation online at
http://httpd.apache.org/docs/2.2/.
Immediately after the AccessFileName
directive, a set of Files
tags apply access control to any file beginning with a .ht
. These directives deny Web access to any .htaccess
files (or other files which begin with .ht
) for security reasons.
AddHandler cgi-script .cgi
This directive enables CGIs outside of the
cgi-bin
to function in any directory on the server which has the
ExecCGI
option within the directories container. Refer to
Directory for more information about setting the
ExecCGI
option for a directory.
In addition to CGI scripts, the AddHandler
directive is used to process server-parsed HTML and image-map files.
AddType application/x-tar .tgz
CacheEnable
— Specifies whether the cache is a disk, memory, or file descriptor cache. By default CacheEnable
configures a disk cache for URLs at or below /
.
CacheRoot
— Specifies the name of the directory containing cached files. The default CacheRoot
is the /var/httpd/proxy/
directory.
CacheSize
— Specifies how much space the cache can use in kilobytes. The default CacheSize
is 5
KB.
The following is a list of some of the other common cache-related directives.
CacheMaxExpire
— Specifies how long HTML documents are retained (without a reload from the originating Web server) in the cache. The default is 24
hours (86400
seconds).
CacheLastModifiedFactor
— Specifies the creation of an expiry (expiration) date for a document which did not come from its originating server with its own expiry set. The default CacheLastModifiedFactor
is set to 0.1
, meaning that the expiry date for such documents equals one-tenth of the amount of time since the document was last modified.
CacheDefaultExpire
— Specifies the expiry time in hours for a document that was received using a protocol that does not support expiry times. The default is set to 1
hour (3600
seconds).
NoProxy
— Specifies a space-separated list of subnets, IP addresses, domains, or hosts whose content is not cached. This setting is most useful for Intranet sites.
The default CustomLog
format is the combined
log file format, as illustrated here:
remotehost rfc931 user date "request" status bytes referrer user-agent
By default, very restrictive parameters are applied to the root directory (
/
), using the
Options
(refer to
Options) and
AllowOverride
(refer to
AllowOverride) directives. Under this configuration, any directory on the system which needs more permissive settings has to be explicitly given those settings.
In the default configuration, another Directory
container is configured for the DocumentRoot
which assigns less rigid parameters to the directory tree so that the Apache HTTP Server can access the files residing there.
The
Directory
container can be also be used to configure additional
cgi-bin
directories for server-side applications outside of the directory specified in the
ScriptAlias
directive (refer to
ScriptAlias for more information).
To accomplish this, the Directory
container must set the ExecCGI
option for that directory.
For example, if CGI scripts are located in /home/my_cgi_directory
, add the following Directory
container to the httpd.conf
file:
<Directory /home/my_cgi_directory> Options +ExecCGI </Directory>
Next, the
AddHandler
directive must be uncommented to identify files with the
.cgi
extension as CGI scripts. Refer to
AddHandler for instructions on setting
AddHandler
.
For this to work, permissions for CGI scripts, and the entire path to the scripts, must be set to 0755.
When a user requests the page http://example
/this_directory
/, they get either the DirectoryIndex
page, if it exists, or a server-generated directory list. The default for DirectoryIndex
is index.html
and the index.html.var
type map. The server tries to find either of these files and returns the first one it finds. If it does not find one of these files and Options Indexes
is set for that directory, the server generates and returns a listing, in HTML format, of the subdirectories and files within the directory, unless the directory listing feature is turned off.
http://example.com/foo.html
The server looks for the following file in the default directory:
/var/www/html/foo.html
Important
To be valid, the message must be enclosed in a pair of double quotes "
.
This directive has been deprecated for the configuration of virtual hosts.
By default, Group
is set to apache
.
To conserve resources on the server, HostnameLookups
is set to off
by default.
If hostnames are required in server log files, consider running one of the many log analyzer tools that perform the DNS lookups more efficiently and in bulk when rotating the Web server log files.
The test in the IfDefine
tags is a parameter name (for example, HAVE_PERL
). If the parameter is defined, meaning that it is provided as an argument to the server's start-up command, then the test is true. In this case, when the Web server is started, the test is true and the directives contained in the IfDefine
tags are applied.
The path to these configuration files can be absolute or relative to the ServerRoot
.
Important
For the server to use individually packaged modules, such as mod_ssl
, mod_perl
, and php
, the following directive must be included in Section 1: Global Environment
of httpd.conf
:
Include conf.d/*.conf
First, the Web server looks in the requested directory for a file matching the names listed in the DirectoryIndex
directive (usually, index.html
). If an index.html
file is not found, Apache HTTP Server creates an HTML directory listing of the requested directory. The appearance of this directory listing is controlled, in part, by the IndexOptions
directive.
The default configuration turns on FancyIndexing
. This means that a user can re-sort a directory listing by clicking on column headers. Another click on the same header switches from ascending to descending order. FancyIndexing
also shows different icons for different files, based upon file extensions.
The AddDescription
option, when used in conjunction with FancyIndexing
, presents a short description for the file in server generated directory listings.
IndexOptions
has a number of other parameters which can be set to control the appearance of server generated directories. The IconHeight
and IconWidth
parameters require the server to include HTML HEIGHT
and WIDTH
tags for the icons in server generated webpages. The IconsAreLinks
parameter combines the graphical icon with the HTML link anchor, which contains the URL link target.
By default
Keepalive
is set to
off
. If
Keepalive
is set to
on
and the server becomes very busy, the server can quickly spawn the maximum number of child processes. In this situation, the server slows down significantly. If
Keepalive
is enabled, it is a good idea to set the the
KeepAliveTimeout
low (refer to
KeepAliveTimeout for more information about the
KeepAliveTimeout
directive) and monitor the
/var/log/httpd/error_log
log file on the server. This log reports when the server is running out of child processes.
If the Apache HTTP Server is configured to listen to a port under 1024, only the root user can start it. For port 1024 and above, httpd
can be started as a regular user.
The Listen
directive can also be used to specify particular IP addresses over which the server accepts connections.
For instance, to allow people connecting from within the server's domain to see status reports, use the following directives:
<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from <.example.com>
</Location>
Replace <.example.com>
with the second-level domain name for the Web server.
To provide server configuration reports (including installed modules and configuration directives) to requests from inside the domain, use the following directives:
<Location /server-info> SetHandler server-info Order deny,allow Deny from all Allow from <.example.com>
</Location>
Again, replace <.example.com>
with the second-level domain name for the Web server.
The following are the format options if the CustomLog
directive is set to combined
:
-
%h
(remote host's IP address or hostname)
Lists the remote IP address of the requesting client. If HostnameLookups
is set to on
, the client hostname is recorded unless it is not available from DNS.
-
%l
(rfc931)
Not used. A hyphen - appears in the log file for this field.
-
%u
(authenticated user)
Lists the username of the user recorded if authentication was required. Usually, this is not used, so a hyphen - appears in the log file for this field.
-
%t
(date)
Lists the date and time of the request.
-
%r
(request string)
Lists the request string exactly as it came from the browser or client.
-
%s
(status)
Lists the HTTP status code which was returned to the client host.
-
%b
(bytes)
Lists the size of the document.
-
%\"%{Referer}i\"
(referrer)
Lists the URL of the webpage which referred the client host to Web server.
-
%\"%{User-Agent}i\"
(user-agent)
Lists the type of Web browser making the request.
Note
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.
To enable name-based virtual hosting, uncomment the NameVirtualHost
configuration directive and add the correct IP address. Then add additional VirtualHost
containers for each virtual host as is necessary for your configuration.
By default, in the DocumentRoot
directory, Options
is set to include Indexes
and FollowSymLinks
. Indexes
permits the server to generate a directory listing for a directory if no DirectoryIndex
(for example, index.html
) is specified. FollowSymLinks
allows the server to follow symbolic links in that directory.
Note
Options
statements from the main server configuration section need to be replicated to each
VirtualHost
container individually. Refer to
VirtualHost for more information.
Redirect /<old-path>
/<file-name>
http://<current-domain>
/<current-path>
/<file-name>
In this example, replace <old-path>
with the old path information for <file-name>
and <current-domain>
and <current-path>
with the current domain and path information for <file-name>
.
In this example, any requests for <file-name>
at the old location is automatically redirected to the new location.
For more advanced redirection techniques, use the
mod_rewrite
module included with the Apache HTTP Server. For more information about configuring the
mod_rewrite
module, refer to the Apache Software Foundation documentation online at
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html.
It is possible to establish directories for storing executables outside of the
cgi-bin/
directory. For instructions on doing so, refer to
AddHandler and
Directory.
By default, ServerAdmin
is set to root@localhost
.
A common way to set up ServerAdmin
is to set it to webmaster@example.com
. Once set, alias webmaster
to the person responsible for the Web server in /etc/aliases
and run /usr/bin/newaliases
.
The following is a sample ServerName
directive:
ServerName www.example.com:80
When specifying a ServerName
, be sure the IP address and server name pair are included in the /etc/hosts
file.
ServerSignature
can be set to EMail
which adds a mailto:ServerAdmin
HTML tag to the signature line of auto-generated responses. ServerSignature
can also be set to Off
to stop Apache from sending out its version number and module information. Please also check the ServerTokens
settings.
Note
From version 2.0, the SuexecUserGroup
directive replaced the Apache HTTP Server 1.3 configuration of using the User
and Group
directives inside the configuration of VirtualHosts
sections.
For more information about
AddType
, refer to
AddType.
UseCanonicalName
is set to off
by default.
By default User
is set to apache
.
This directive has been deprecated for the configuration of virtual hosts.
Note
For security reasons, the Apache HTTP Server does not run as the root user.
The name for the subdirectory is set to public_html
in the default configuration. For example, the server might receive the following request:
http://example.com
/~username
/foo.html
The server would look for the file:
/home/username/public_html/foo.html
In the above example, /home/username/
is the user's home directory (note that the default path to users' home directories may vary).
Make sure that the permissions on the users' home directories are set correctly. Users' home directories must be set to 0711. The read (r) and execute (x) bits must be set on the users' public_html
directories (0755 also works). Files that are served in a users' public_html
directories must be set to at least 0644.
A commented
VirtualHost
container is provided in
httpd.conf
, which illustrates the minimum set of configuration directives necessary for each virtual host. Refer to
Section 11.7, “Virtual Hosts” for more information about virtual hosts.
Note
The default SSL virtual host container now resides in the file /etc/httpd/conf.d/ssl.conf
.