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.
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.
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 .
This directive limits the number of requests allowed per connection while “KeepAlive” is “On”. Default value is 100.
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.
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.
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.
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.
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).
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.
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.
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.
This is called a sectional directive as it encloses a group of directives that applies to the specified directory.
Allow from all
We can now go through the directives included above.
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”
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
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.
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.
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.
You might also like
Category: WEB SERVERS