Text-based Configuration

The server configuration file is httpd.conf, a simple text file that Stronghold reads each time it starts. This chapter introduces you to this file and shows you how to:

Once you understand the configuration concepts discussed here, refer to the Apache Desktop Reference to find specific directives to customize the httpd.conf file.

Each time you edit the configuration file, you must reload the server in order to apply your changes. See Reloading Stronghold for details.


Locating the Configuration Components

Stronghold for Red Hat Linux Advanced Server

The configuration files for Stronghold for Red Hat Linux Advanced Server are in various locations:

Stronghold on Cross-Platform Systems

All Stronghold configuration files are in the ServerRoot/conf/ directory.

The httpd.conf file, Stronghold’s main configuration file, references:

For detailed information about Configuration, see the Apache Desktop Reference by opening a browser to http://your.server/stronghold/ and clicking on Apache manual on the side bar.

For detailed information about php4.conf, open a browser to http://your.server/stronghold/ and click on PHP on the side bar.

The ServerRoot/conf/ssl/ directory contains the configuration files for OpenSSL:

The ServerRoot/conf/tomcat/ directory contains the configuration for Tomcat Java Servlet Engine (if it is installed). For configuration information, open a browser to http://your.server/stronghold/ and click on Tomcat documentation on the side bar.


Using Directives

Directives are configuration commands. Each directive controls a different aspect of Stronghold’s behavior, including how it treats the objects on the site. Different directives take different kinds of values as arguments, such as:

Since many of the objects on your server require special treatment, each object can have its own configuration within httpd.conf. An object’s configuration describes deviations from the global configuration. This granularity gives Stronghold its enormous flexibility.

Containers

Directives can be applied in different "contexts" where a directive’s context is the scope in which it applies. The configuration file uses containers to constrain directives to a context such as a particular virtual host, a URL, an HTTP access method, a directory, or a file. For example:

   <Directory /logos/jpegs>
   ...
   </Directory>

This example shows an opening container tag, which specifies an object on the server, followed by a closing container tag that begins with a slash (/). The directives that apply only to the /logos/jpegs directory go between the opening and closing container tags.

When entering configuration directives, use the following guidelines:

These are the available containers:

Each of these can be nested inside the others, with the following exceptions:

Directives that appear outside all containers apply globally. The server reads them first. Directives inside containers are processed in the following order:

The processing order above applies to containers inside <VirtualHost> containers.

This processing order allows more specific containers to override the directives inside more general containers. Except for <Directory> containers without regular expressions, containers of each type are processed in the order in which they appear. Configuration elements inserted with the Include directive are treated as if they are located at the point of inclusion.

Wildcards

Wildcards are a simple method of denoting variable values. Containers can take wildcards in place of ordinary hostnames, paths, and so on. Some directives can also take wildcards as values.

There are two wildcards:
WildcardDescription
*Matches zero or more of any string
? Matches exactly one of any string, that is, the first match found

For example, imagine that Stronghold is an internal server private proxy on your organization’s local area network (LAN). Each host on the LAN has a hostname that ends with your organization’s basic domain name, such as redhat.com. The asterisk wildcard can be used to restrict access so that your server responds only to hosts on the LAN:

   AddAlt "JPEG banner" banner*.jpeg

In this example, any filename that begins with "banner" and has the .jpeg filename extension is given the "JPEG banner" description in the directory index listings. Any number of filenames qualify, such as banner1.jpeg, banner_advertisement.jpeg, and so on.

Regular Expressions

Regular expressions are patterns that describe a set of strings. They consist of any number of ordinary characters and metacharacters. When combined as a regular expression, these can match zero or more real strings. Stronghold supports POSIX Extended Regular Expressions (EREs).

Some directives can take regular expressions as values. Containers can also take regular expressions as long as the beginning of the expression is denoted with a tilde (~). For example:

   <Directory ~ "^/www/.*/[a-z]{3}">
   ...
   </Directory>

Stronghold also includes several "match" containers designed specifically for regular expressions. The tilde character is not required in these containers. Where regular expressions are required, use the match containers. For example, the <DirectoryMatch> container can accomplish the same task as the <Directory> container above:

   <DirectoryMatch "^/www/.*/[a-z]{3}">
   ...
   </DirectoryMatch>

Metacharacters modify regular characters within a regular expression:

Metacharacter Description
(characters) all of characters
[characters] any of characters
[^characters] none of characters
[a-z] all characters from a to z
. wildcard; matches any single character
? 0 or 1 of the preceding character
* 0 or more of the preceding character
+ 1 or more of the preceding character
{n} exactly n of the preceding character
{n,} n or more of the preceding character
{,n} no more than n of the preceding character
{n,m} at least n but no more than m of the preceding character
\x literal character; the backslash (\) escapes special characters
^ start of line
$ end of line

Regular expressions can be combined. Expression A and expression B can be combined in two ways:


Configuring Virtual Hosts

In addition to the "main" host, the server can support a number of virtual hosts. To function properly, virtual hosts must meet some basic configuration requirements. In addition, the server must be able to distinguish between virtual hosts. Virtual hosts can be distinguished in three different ways:


Name-based virtual hosts do not work with SSL/TLS because SSL and TLS encrypt all HTTP headers—including the Host header required to determine which name-based virtual host is being addressed.

Virtual Host Configuration Requirements

Each SSL/TLS virtual host must have:

Each virtual host should be designated by its IP address, even if it is not an IP-based virtual host, to avoid time-consuming DNS lookups. Because regular hosts and SSL/TLS hosts use different ports and require separate configurations, each virtual host container tag must also specify a port number, even if it does not pertain to a port-based virtual host.


If Stronghold is running as an SSL/TLS-only server, it is not necessary to specify a port because all hosts listen on the globally-configured SSL/TLS port.

Each <VirtualHost> container should include these directives:

Directive Description
ServerName  The hostname of this host; it must be a fully-qualified domain name that resolves to the IP number specified in the opening container tag.
ServerAdmin  The email address of this host’s administrator.
DocumentRoot  The root document directory for this host, necessary to resolve URLs; requests are fulfilled from this directory except where configured otherwise.
CustomLog  A consolidated access/error log for this host. Combining these in a single custom log saves file descriptors on sites that support many hosts. Optionally to give each virtual host its own TransferLog and ErrorLog if file descriptors are not an obstacle.

For example:

   <VirtualHost 205.254.204.194:80>
   ServerName www.example.com
   ServerAdmin webmaster@example.com
   DocumentRoot /www/htdocs/example
   CustomLog logs/example.log "%h %l %u %t \"%r\" %s %b"
   </VirtualHost>

Each SSL/TLS container must include the directives above (except CustomLog), plus these SSL/TLS-specific directives:

Directive Description
SSLEngine on  Enables SSL/TLS functionality for this virtual host. This directive was formerly SSLFlag.
SSLCertificateKeyFile  The path to the key file for this host relative to ServerRoot/conf/ssl/, usually private/hostname.key
SSLCertificateFile  The path to the certificate file for this host relative to ServerRoot/conf/ssl/, usually certs/hostname.cert
SSLLog  The SSL/TLS log file for this host relative to ServerRoot/, such as logs/ssl/hostname_ssl_engine_log. This directive used to be SSLLogFile.

For example:

   <VirtualHost www.example.com:443>
   ServerName www.example.com
   DocumentRoot /usr/local/www/htdocs/example
   ServerAdmin webmaster@example.com
   SSLEngine on
   SSLCertificateKeyFile private/example.key
   SSLCertificateFile certs/example.cert
   SSLLog logs/ssl/example_cipher_log
   </VirtualHost>

Note that the opening container tag must specify the SSL/TLS port number, usually port 443. Port-based virtual hosts each use a different port number.

IP-Based Virtual Hosts

When multiple IP addresses are assigned to the server machine, each virtual host can be distinguished with its own IP address. This is the recommended virtual host configuration because it:

The means for configuring multiple IP addresses at the system level vary from platform to platform, and the operating system documentation can provide assistance. Once multiple IP support is established at the system level, containers for each virtual host can be entered in the configuration file. When entering a virtual host container, specify an IP address and a port number, like this:

   <VirtualHost 140.174.185.14:80>

Stronghold simply matches the IP address of each incoming request with an IP address in one of the virtual host containers. When responding, Stronghold uses the hostname specified by that container’s ServerName directive.

Port-Based Virtual Hosts

Port-based virtual hosts may share a single IP address, but each is distinguished by two unique port numbers: one for ordinary transactions, and one for SSL/TLS-secured transactions. For example:

   <VirtualHost 127.65.42.1:880>
   ServerAdmin webmaster@example.com
   DocumentRoot /usr/local/www/htdocs/example
   ServerName www.example.com
   </VirtualHost>
   <VirtualHost 127.65.42.1:4430>
   ServerAdmin webmaster@example.com
   DocumentRoot /usr/local/www/htdocs/example
   ServerName www.example.com
   SSLEngine on
   SSLCertificateKeyFile private/www.example.com.key
   SSLCertificateFile certs/www.example.com.cert
   </VirtualHost>

In this example, no other virtual hosts on this server can use port 880 or 4430. Each port-based virtual host must be assigned ports for SSL/TLS and regular (non-secure) transactions that are not used by any other virtual hosts on the server.

Under this scheme, every link in every file belonging to a host must take one of two forms:

Inevitably, users enter URLs without port numbers. When this happens under a port-based virtual host scheme, port 80 receives the request. When a user specifies HTTPS without a port number, port 443 receives the request. Be sure that one of the hosts listens on ports 80 and 443 and that its main page contains links to the virtual host ports.


If port-based virtual hosts are configured, name-based virtual hosts cannot be present in the same server configuration.

Name-Based Virtual Hosts

Name-based virtual host support depends largely on the compliance of browsers with the HTTP/1.1 protocol, which requires the Host header in all client requests. The Host header enables the server to determine which host is being requested. It also allows multiple virtual hosts to share a single IP address. The latest browsers, including Netscape Navigator and Microsoft Internet Explorer, support HTTP/1.1. Many older browsers do not.

Name-based virtual hosts do not support SSL/TLS. Under SSL and TLS, all HTTP headers are encrypted, including the Host header required to determine which host is being requested. Without the Host header, Stronghold cannot determine which virtual host configuration to apply. Without the correct configuration, Stronghold also cannot determine which site certificate to send or which private key to use when decrypting SSL/TLS requests.

The Domain Naming System (DNS) must be configured to point all hostnames to the server IP address. The means for doing this vary from platform to platform, and the operating system documentation can provide assistance.

For each IP address that is used for name-based virtual hosts, the server’s global configuration must contain a NameVirtualHost directive. The IP address specified by NameVirtualHost is used only for name-based virtual hosts; the main server and other types of virtual hosts never respond to that IP number. This means that a separate IP address must be reserved for use with name-based virtual hosts. If you have only one IP address, all hosts (including the main host) must be name-based virtual hosts in order to work.

For example:

   <ServerRoot>/www
   ServerName www.main.net
   DocumentRoot /www/main/htdocs
   NameVirtualHost 205.254.204.194
   <VirtualHost 205.254.204.194:80>
   ServerName www.kayak.com
   DocumentRoot /www/kayak/htdocs
   ...
   </VirtualHost>
   <VirtualHost 205.254.204.194:80>
   ServerName www.anorak.com
   DocumentRoot /www/anorak/htdocs
   ...
   </VirtualHost>

When it receives a request, Stronghold reads the Host header to get the hostname. If the host is www.kayak.com, the server looks in /www/kayak/htdocs for the requested document. If it is www.anorak.com, Stronghold uses the /www/anorak/htdocs directory instead.

Now imagine that 205.254.204.194 is the only IP address available. In that case, the globally configured server never responds to a request, because that IP address is reserved for name-based virtual hosts. To solve this problem, create a name-based virtual host configuration to represent the main server. For example:

   <ServerRoot>/www
   ServerName www.main.net
   DocumentRoot /www/main/htdocs
   NameVirtualHost 205.254.204.194
   <VirtualHost 205.254.204.194:80>
   ServerName www.main.net
   DocumentRoot /www/main/htdocs
   ...
   </VirtualHost>
   <VirtualHost 205.254.204.194:80>
   ServerName www.kayak.com
   DocumentRoot /www/kayak/htdocs
   ...
   </VirtualHost>
   <VirtualHost 205.254.204.194:80>
   ServerName www.anorak.com
   DocumentRoot /www/anorak/htdocs
   ...
   </VirtualHost>

In the absence of a Host header, any request for a name-based virtual host is still directed to the main server’s pages. You must, therefore, provide a link from the main server’s pages to the name-based virtual hosts. Furthermore, any links in the virtual host’s pages should be relative in order to work with older browsers. This is a cumbersome approach and may become less important as browsers evolve.

Certificates and Key Pairs for Virtual Hosts

Because Microsoft Internet Explorer and Netscape Navigator check the URL against the hostname on any server certificate, each SSL/TLS virtual host requires a separate certificate. The genkey utility generates a key pair, requests a certificate, and installs a self-signed temporary certificate for each SSL/TLS virtual host. The key pair is saved at ServerRoot/conf/ssl/private/hostname.key. Along with the key pair, genkey generates a certificate signing request (CSR) to send to a Certification Authority (CA), typically Verisign, GeoTrust, or Thawte. For more detailed information about certificates, certification authorities, Versign, GeoTrust, or Thawte, see Authentication and Encryption.


Reconfiguring an SSL/TLS-Only Server

When you install Stronghold Web Server 4.0, you have the option to enter "0" when prompted for a port to use for unsecured transactions. This disables normal, unsecured transactions. If you later decide to introduce non-secure transactions on your server, follow these instructions.

To convert a secure-only server to a dual secure/nonsecure server:

  1. Open httpd.conf in a text editor.
  2. Insert the following virtual host configuration below all virtual hosts:
       Listen 80
       <VirtualHost_default_:80> 
       Servername 
       ServerAdminemail-address SSLEngine off
       DocumentRoot /full/path/to/document/root
       TransferLog logs/error/access_log 
       ErrorLog logs/error_log
       </VirtualHost>
    

    This virtual host responds to HTTP requests for the main host.

  3. Run reload-server to reload the server. Stronghold rereads the httpd.conf file and makes these changes. If your also add nonsecure counterparts for your existing, SSL/TLS-only virtual hosts, you must first make sure those hosts use an IP/port number configuration. For example:
       <VirtualHost 209.60.53.41:443>
    
  4. For each IP- or port-based SSL/TLS virtual host, add a nonsecure counterpart. Insert any new, non-SSL virtual hosts above the <Virtualhost_default_:80> container. Each must also use an IP address and a port number. For example, the nonsecure counterpart to the example above looks like this:
       <VirtualHost 209.60.53.41:80>
       ServerName 
       ServerAdmin login@
       SSLEngine off
       DocumentRoot /full/path/to/document/root
       TransferLog logs/_access_log
       ErrorLog logs/_error_log
       </VirtualHost>
    

Single, HTTP-only virtual hosts with no counterparts can be name-based.