Using Apache Configuration Directives

An Apache directive is a command in one of Apache's configuration files. Apache's primary configuration file is httpd.conf , located in the /etc/httpd/conf directory.

Using the directives in Apache's configuration files, you can control the behavior of the Apache Web server.

Although you can use the Linux Configuration applet to control basic Apache configuration, most Apache administrators are used to working with directives and httpd.conf rather than a visual administration tool. Fortunately, the file is well commented, so it is pretty easy to understand what each section is supposed to do.

A hash mark (#) at the beginning of a line in the configuration file indicates a comment. Directives that are commented out with a hash mark can be activated by removing the mark.

This section covers some of the more important core Apache directives in httpd.conf in the order that they appear in the file. For more information on editing the file, you should consult the documentation at http://www.apache.org. For information on modules, see the sidebar "Apache modules."

Setting the server type

The server type can be set as either standalone or inetd. Here are the lines from the configuration file:

# ServerType is either inetd, or standalone. ServerType standalone

The default Red Hat Linux 6 Apache setup is standalone—this is also the general Apache default—and it is unlikely that you will want to change this. However, you should know that the setting exists.

In the standalone method, Apache listens to a particular port (or ports) for connection requests. When a Web client makes a request on that port, Apache launches a child Web server process to service it. This is, essentially, a pooled connection setup.

The other method, inetd, is the Internet daemon responsible for listening for connection requests on all ports with numbers less than 1024. In the inetd method, when inetd intercepts a request for a Web server connection, it launches an instance of Apache to handle the request. After the request has been serviced, the instance of the Web server exits.

Setting the port

The Port setting specifies the port that Apache listens on. The default setting is port 80. Two other directives, Listen and BindAddress, can add ports.

# Port: The port the standalone listens to. For ports < 1023, you will
# need httpd to be run as root initially.
Port 80

Tuning the engine

The next group of directives tune the way Apache works. These settings affect such matters as the number of child instances of Apache that can be created and the maximum number of clients that can be logged on simultaneously. For detailed descriptions, read the comments in httpd.conf.

Here are the directives with the Red Hat Linux 6 defaults:

StartServers 10
...
MinSpareServers 8
MaxSpareServers 20
...
KeepAlive 0
...
KeepAliveTimeout 15
...
MaxClients 150
...
MaxRequestsPerChild 100

Setting the server root

The ServerRoot setting establishes the directory where the Apache configuration, error, and log files are stored.

Here is the Red Hat Linux 6 /Apache default:

ServerRoot /etc/httpd

Setting host name lookups

The Hostname Lookups directive, if set to on, performs a lookup of the IP addresses of the client browser and writes the domain names in the server logs. For example, 204.0.134.135 is translated as

http://www.bearhome.com

The default setting is off:

HostnameLookups off

Setting the server name

The default server name is localhost:

ServerName localhost

You can set ServerName to any value you want provided the name will resolve to your host.

Using Listen

Listen directs Apache to respond to requests made on particular IP addresses, IP address and port combinations, or just a port by itself: for example,

Listen 24.6.255.24:80

Listen 24.6.255.24:8080

Setting virtual host directives

Virtual hosts are specified in httpd.conf using angle brackets and a syntax that resembles HTML. (Directives using this syntax are referred to as container directives.)

Here's one example (see "Using development virtual hosts" earlier in this chapter for the Linux Configuration applet settings that produced this virtual host directive):

<VirtualHost 24.6.255.24:8080>
  ServerAdmin [email protected]
  ServerName 14.6.255.24:8080
  DocumentRoot /www/linuxbear
</VirtualHost>
			

Here's another example:

<VirtualHost 201.12.34.34>
  ServerName www.snakesrus.com
  DocumentRoot /www/serpents
</VirtualHost>
			

Apache modules

Apache is made up of modules, which are code libraries that are compiled together to create the working version of Apache. Modules have their own directives and vary from extremely functional to experimental.

You have a great deal of flexibility as to which modules you include in Apache, but any choice other than the default involves recompiling. Many important modules—such as those that enable server-side includes and CGI execution—are not included in the default Red Hat binary distribution.

You can determine which modules are loaded in Apache by typing

/etc/bin/httpd –l

at the command prompt.

If you'd like to decide for yourself which modules to include in your compilation, you can download the Apache source code from

http://www.apache.org/dist/


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.79.65