Apache is structured mainly
through its configuration files. You can add directives to the httpd.conf file to
control Apache’s behavior.
There are two types of Apache
directives: single line entries and block directives.
ServerName your_company.com
-
Block directives that have a
beginning line and an ending line. Block directives are used to group together
a set of directives. For example:
<VirtualHost IP:80>
ServerName abc.com
ServerAdmin webmaster@abc.com
DocumentRoot
/home/username/www/abc.com
</VirtualHost>
Block directives are enclosed in
angle brackets ("< >") and always have a beginning and ending directive.
The ending directive has a forward slash ("/").
Server
Operation Directives
Apache can utilize a large number
of directives. When you add modules, the modules produce even more directives.
The
LoadModule Directive
The LoadModule directive
instructs the Apache Web server software to load shared object libraries at
startup. This should be the first directive in the configuration file so the
module is available before the Web server uses it. The following is an example:
LoadModule foo_module
modules/mod_foo.so
Refer to "Modules" on
for more information on Apache modules.
The HostnameLookups
Directive
The Apache Web server is
configured by default to keep a log of the clients that access resources on
your Web site. The log includes the hostname (i.e. some.remote.host) or just
the IP address (i.e. 32.64.128.16). The value is set to "off" by
default to improve your server performance. Additional latency is introduced
into the server response process when the Web server is required to perform a
hostname lookup that translates IP addresses into domain names.
Sites with even moderate loads
should leave this directive off because hostname lookups can take considerable
amounts of time.
The following is an example:
HostnameLookups off
For more information, go to:
The ServerAdmin
Directive
The ServerAdmin directive defines
the e-mail address the server includes in error messages that it returns to the
client.
The following is an example:
ServerAdmin
webmaster@your_company.com
For more information, go to:
The ServerRoot Directive
The ServerRoot directive defines
the directory in which the server resides. The default directory is /usr/local/apache, since
this directory contains the subdirectories conf and logs. Relative paths for
other configuration files are defined with respect to the ServerRoot directory.
The following is an example:
ServerRoot /usr/local/apache
For more information, go to:
The
ErrorLog Directive
When your Web server encounters
an error, it will use the definition specified in the ErrorLog directive to
handle the error. Typically, a filename is specified to which your Web server
appends the error information. If the filename definition does not begin with a
slash ("/"), then it is assumed to be relative to the
ServerRoot. If the filename begins with a pipe ("|"), then it is
assumed to be a command that is to be spawned by the Web server to handle the
error information.
The following is an example:
ErrorLog logs/error_log
For more information, go to:
The LogFormat Directive
The LogFormat directive sets the
format of the default log file named by the TransferLog directive. You can also
use this directive to define custom log file format types. Each log format type
is defined by a format declaration enclosed in quotations followed by an
optional identifier or a nickname. Examples of some LogFormat directives are
included below. For more information about using log formats effectively, see
"Web Logs"
The format declaration member of
each LogFormat directive can contain literal characters copied into the log
files, and “%” directives that are replaced in the log file. A sample of
some of the “%” directives are shown below. (A complete list can be found
on the Apache Web site.)
%b: Bytes sent, excluding HTTP
headers.
%f: Filename
%h: Remote host
%r: First line of request
%s: Status. For requests that got
internally redirected, this is status of the *original* request ---
%>s for the last.
%t: Time, in common log format
time format
%u: Remote user
Logformat "format
declaration" identifier
LogFormat "%h %l %u %t
\"%r\" %>s %b \"%{Referrer}i\"
\"{User-Agent}i\"" combined
LogFormat "%h %l %u %t
\"%r\" %>s %b" common
LogFormat "%{Referrer}i
-> %U" referrer
LogFormat
"%{User-Agent}I" agent
For more information, go to:
Changing
LogFormat
You can change the Web server log
file format to the common log format (separate log files for the access, agent,
and referrer data) by modifying your Web server configuration file /www/conf/httpd.conf
like this:
# common log format
LogFormat "%h %l %u %t
\"%r\" %>s %b"
# combined log format
#LogFormat "%h %l %u %t
\"%r\" %>s %b \"%{Referrer}i\"
\"%{User-Agent}i\""
# The location of the access
logfile
# If this does not start with /,
ServerRoot is prepended to it.
TransferLog logs/access_log
# If you would like to have a
separate agent and referrer logfile
# uncomment the following
directives.
ReferrerLog logs/referrer_log
AgentLog logs/agent_log
You can also define your own log
format by modifying the LogFormat directive above. After making the changes
above, be sure to restart your VPS v2 Virtual Server Web server.
The TransferLog
Directive
The TransferLog directive
identifies the location of a file that will contain a record of all requests
made to your Web server.
If you are using the CustomLog
directive to define the format of your log files, the format of your
TransferLog file will be defined by the most recent LogFormat directive (or
Combined Log Format if no other default format has been specified). If you
would like entries in your transfer log to be formatted with the Common Log
Format, you will need to create a custom LogFormat definition.
You can also process your
Transfer Log entries with an external application by defining your TransferLog
using a file pipe ("|").The following is an example:
TransferLog logs/access_log
TransferLog "|rotatelogs
/www/logs/access_log 86400"
For more information, go to:
The ReferrerLog
Directive
The ReferrerLog directive is used
to identify the location of a file that will contain a record of all referrer
information (i.e. information about Web sites that link to and
"referred" users to your Web site). By default, your server is
configured in the combined log format. As such, the referrer information is
included in the access_log. If you want a separate log for referrer
information, see "Changing LogFormat"
The following is an example:
RefererLog logs/referrer_log
For more information, go to:
The AgentLog Directive
The AgentLog directive is used to
identify the location of a file that contains a record of all browser agent
information. By default, your server is configured in the combined log format.
As such, the agent information is included in the access_log. If you want a
separate log for agent information, see "Changing the LogFormat"
The following is an example:
AgentLog logs/agent_log
For more information, go to:
The ServerName DirectiveThe ServerName directive sets the
hostname of the Web server.
The following is a usage example:
ServerName some_domain.name
For more information, go to:
The KeepAlive Directive
The KeepAlive extension to HTTP,
as defined by the HTTP/1.1 draft, allows persistent connections. These
long-lived HTTP sessions allow multiple requests to be sent over the same TCP
connection and in some cases have been shown to result in an almost 50% speedup
in latency times for HTML documents with multiple images. The KeepAlive
directive enables or disables KeepAlive support. Set the value of this
directive to "on" in order to enable persistent connections. Set the
value of the directive to "off" to disable KeepAlive support. The
maximum number of requests that you would like the Web server to support per
connection is defined with the MaxKeepAliveRequests directive.
The following is an example:
KeepAlive on
For more information, go to:
The MaxKeepAliveRequests
Directive
The MaxKeepAliveRequests
directive limits the number of requests allowed per connection when KeepAlive
is on. If it is set to 0, unlimited requests will be allowed. It is recommended
that this setting be kept to a high value for maximum server performance.
The following is an example:
MaxKeepAliveRequests 100
For more information, see:
The KeepAliveTimeout
Directive
The KeepAliveTimeout directive
defines the number of seconds the Web server waits for a subsequent request
before closing the connection to the remote host.
The following is an example:
KeepAliveTimeout 15
For more information, go to:
The MaxRequestsPerChild
Directive
The MaxRequestsPerChild directive
sets the limit on the number of requests that an individual child server
process will handle. After the MaxRequestsPerChild requests has reached its
limit, the child process will die. If MaxRequestsPerChild is 0, then the
process will never expire.
Setting MaxRequestsPerChild to a
non-zero limit has two beneficial effects. First, it limits the amount of memory
that process can consume by (accidental) memory leakage. Second, by
giving processes a finite lifetime, it helps reduce the number of processes
when the server load reduces.
The following is an example:
MaxRequestsPerChild 0
For more information, go to:
The VirtualHost
Directive
The VirtualHost directive allows
you to configure your Web server to subhost multiple domain names.
The following is an example:
<VirtualHost IP:80>
User username
Group groupname
ServerName domain.ext
ServerAdmin
username@domain.ext
DocumentRoot
/home/username/www/domain.ext
ScriptAlias /cgi-bin/
"/home/username/www/cgi-bin/"
<Directory
/home/username/www/cgi-bin>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
ErrorLog
/home/username/www/logs/domain.ext-error_log
CustomLog /home/username/www/logs/domain.ext-access_log
combined
</VirtualHost>
Note: All log files
are owned by root and count against his quota. Subhosts can only view the log
files and cannot modify them. To change ownership of the log files type the
following at the command prompt as root:
% chown username:groupname logfile
For more information, go to:
Our Technical Support Pages
The DocumentRoot
Directive
The DocumentRoot is the location
from which Web pages are served, such as:
DocumentRoot
/home/username/usr/local/apache/htdocs
For more information, go to:
The DirectoryIndex
Directive
When a URL request is received
that does not explicitly identify a resource by name, (e.g.
http://www.your_company.com), your Web server will attempt to retrieve the
files defined by the DirectoryIndex directive. Several files may be defined.
The Web server will return the first one that it finds.
The following is an example:
DirectoryIndex index.php
index.htm
A request for
http://www.your_company.com would return http://www.your_company.com/index.php
if it existed, then http://www.your_company.com/index.htm if it existed, and so
on until a match is found. If no match is found, then an index of the files
contained in the directory is returned.
For more information, go to:
The FancyIndexing,
IndexOptions, AddIcon, and IndexIgnore Directives
As noted above, the
DirectoryIndex directive identifies specific files that should be searched for
when a URL request is received that does not explicitly identify a resource. If
the DirectoryIndex search fails and the Indexes option is set for the requested
directory (see the httpd.conf <Directory> directive), then an index of
files is generated and served the client agent. There are several directives
that define the display of such an index of files.
For more information, go to:
The AccessFileName
Directive
When returning a document to a
client, the server looks for access control files in the requested resource
directory as well as its parent directories. The AccessFileName directive sets
the name of the file your Web server will look for to find access control
definitions. For more information about access control files.
The following is an example:
AccessFileName .htaccess
For more information, see:
The DefaultType
Directive
The DefaultType directive defines
a MIME type for resources on your Web server that do not match file extensions
found in your MIME types configuration file.
The following is an example:
DefaultType text/plain
For more information, go to:
The AddLanguage
Directive
The AddLanguage directive is used
to identify resources written in a specific language with a file extension. The
AddLanguage directive is essential for content negotiation, where the server
returns one of several documents based on the language preference of the client
browser. For more information about content negotiation.
The following is an example:
AddLanguage en .en
For more information, go to:
The LanguagePriority
Directive
The LanguagePriority directive
allows you to give precedence to some languages in case of a "tie"
during content negotiation, or if the browser client does not specify a
language priority (which may happen with older browsers). Simply list the
languages in decreasing order of preference. For more information about content
negotiation.
Note: Use of this
directive requires that the mod_negotiation module be loaded. Please refer to
the LoadModule directive explanation for more information.
The following is an example:
LanguagePriority en fr de
For more information, go to:
The Redirect Directive
The Redirect directive is used to
redirect absolute URL pathnames to absolute URL addresses. This is especially
useful if you have resources that have moved from one location to another and
want to "redirect" requests for the document at the old location to
the new location.
The following is an example:
Redirect /path/file.html http://somewhere.else/file.html
Redirect /path/file.html
http://www.your_company.com/newfile.html
Redirect /directory
http://somewhere.else/directory/
Redirect /directory
http://www.your_company.com/newdirectory/
For more information, go to:
The Alias Directive
The Alias directive allows
documents to be stored in the local file system other than under the directory
defined with the DocumentRoot directive.
The following is an example:
Alias /icons/ “/ usr/local/apache/icons/”
For more information, see:
The ScriptAlias Directive
The ScriptAlias directive has the
same behavior as the Alias directive, except that in addition to defining an
alias definition, the directive also marks the target directory as containing
CGI scripts.
The following is an example:
ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
For more information, go to:
The AddType Directive
The AddType directive allows you
to add a new MIME type definition without editing the file defined by the
TypesConfig directive. Your mime.types configuration file is fairly complete,
so you will rarely need the AddType directive.
The following is an example:
AddType text/plain .txt
For more information, go to:
The AddHandler Directive
The AddHandler directive maps a
filename extension to a special handler.
Example:
# To use CGI scripts:
AddHandler cgi-script .cgi
# To use server-parsed HTML files
AddType text/html .shtml
AddHandler server-parsed .shtml
For more information, go to:
The ErrorDocument
Directive
The ErrorDocument directive
defines the location of documents that should be displayed (or scripts that
should be invoked) when the server encounters an error. The directive can map
the error codes to documents or scripts on your local server or on a remote
server.
When the error code is
encountered, the Web server tells the browser client to redirect its request to
the URL you defined with the error code. If no ErrorDocument definition exists
for a specific error code, then the Web server outputs a hard coded error
message that it has defined internally. Common error codes include 401, 403,
404, 406, and 500. Those error codes and their definitions are found in the
following table:
|
Error Code |
Definition |
|
Error Code 401 – Authorization
Failed |
The requested resource required authentication, and the
client failed to provide a valid login/password pair. |
|
Error Code 403 – Permission
Denied |
The client has requested a resource that is forbidden. |
|
Error Code 404 – Resource Not
Found |
The requested resource does not exist on the Web server. |
|
Error Code 406 – Resource Not
Acceptable |
The requested resource was found on the Web server, but it
could not be delivered because the type of the resource is incompatible with
accepted types indicated by the client. |
|
Error Code 500 – Internal
Error |
The requested resource does not exist on the Web server. |
|
Error Code 501 – File Not
Found |
The requested file does not exist of the Web server. |
See "Creating Custom Error
Document Pages" for more information about custom error handling.
The following is an example:
ErrorDocument 401
/error_docs/subscribe.html
ErrorDocument 403
/error_docs/denied.html
ErrorDocument 404
/error_docs/notfound.html
ErrorDocument 406
/cgi-bin/error_scripts/language_handler.pl
ErrorDocument 500
/cgi-bin/error_scripts/script_error.pl
ErrorDocument 501
/errors_docs/filenotfound.html
For more information, go to:
Access Control
Directives
Apache provides control
directives that define a limited scope for the area of effect of a specific
directive. Using these directives, you can define security, control access to
sensitive materials, and identify how certain files should be treated.
The Directory Directive
The Directory directive defines
access control and security settings for the directories that are accessible by
your Web server. Each Directory directive is comprised of several sub
directives. Some of these sub directives include Options, AllowOveride, and
<Limit>. Many of the sub directives that can be included in the
<Directory> definitions can be included in local access control files
(see AccessFileName directive). In most cases, the default <Directory>
definitions included in your httpd.conf file will be adequate for your needs
(the default definitions are included below).
If you need to modify these
definitions, consult the URL references listed below for a thorough
presentation of the <Directory> directive and its sub directives.
The following is an example:
<Directory
"/usr/local/apache/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
For more information, go to:
The
MIME Types File (mime.types)
The MIME types configuration file
determines how your VPS v2 Virtual Server's Web server maps filename extensions to MIME types
that are returned to the browser. Your browser then maps these MIME types to
"helper" applications or in-line plug-ins. Although the default
mime.types configuration file includes a definition of the most common known
MIME types, you are free to modify the file to add support for any additional
MIME type that you desire.
Adding a New MIME Type
Definition
Append the definition to the
existing MIME types in the file in the following format (where type/subtype is
the MIME type of the document whose filename ends with one of the extensions
listed):
type/subtype extension1
extension2 … extensionN
Note: Lines beginning
with a "#" are comment lines and are
ignored by the Web server.
The extension list includes any
number of space-separated filename extensions. Examples of MIME type entries
can be found in the default MIME types file included with your virtual Web
service.
|