Setting up virtual hosts on HTTP Server

Set up virtual hosts on your IBM® HTTP Server for i instance using the IBM Web Administration for i interface.

Virtual hosts allow more than one Web site on one system or Web server. The servers are differentiated by their host name. Visitors to the Web site are routed by host name or IP address to the correct virtual host. Virtual hosting allows companies sharing one server to each have their own domain names. For example, www.company1.com and www.company2.com can both be hosted on the same server. See Virtual hosts on HTTP Server for more information.

You can configure virtual hosts by doing the following:

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.
  4. Select Global configuration from the Server area list.
  5. Expand Server Properties.
  6. Click Virtual Hosts.
  7. Click either the Name-based virtual host tab or the IP-based virtual host tab in the form.

Name-based virtual hosts

The name-based virtual host allows one IP address to host more than one Web site (hostname). This approach allows a single HTTP Server to service requests directed at many different hostnames. This simplifies configuration and use, and requires no additional hardware or software. The main disadvantage to this approach is that the client must support HTTP 1.1 (or HTTP 1.0 with 1.1 extensions) that include the server hostname information inside the HTTP document requests. The latest versions of most browsers support HTTP 1.1 (or HTTP 1.0 with 1.1 extensions), but there are still old browsers that only support HTTP 1.0. For more information on virtual hosts refer to the <VirtualHost> directive.

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.
  4. Select Global configuration from the Server area list.
  5. Expand Server Properties.
  6. Click Virtual Hosts.
  7. Click the Name-based tab in the form.
  8. Click Add under the Named virtual hosts table.
  9. Select or enter an IP address in the IP address column.
    Note: The Web Administration for i provides the IP addresses used by your IBM i system in the IP Address list; however, you will need to provide the hostname associated with the address you choose and register the hostname with your Domain Name Server (DNS).
  10. Enter a port number in the Port column.
  11. Click Add under the Virtual host containers table in the Named host column.
  12. Enter the fully qualified server hostname for the virtual host in the Server name column.
    Note: Make sure the server hostname you enter is fully qualified and associated with the IP address you selected.
  13. Enter a document root for the virtual host index file or welcome file in the Document root column.
  14. Click Continue.
  15. Click OK.

IP-based virtual hosts

The IP-based virtual host requires one IP address per Web site (host name). This approach works very well, but requires a dedicated IP address for every virtual host. For more information on virtual hosts refer to the <VirtualHost> directive.

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.
  4. Select Global configuration from the Server area list.
  5. Expand Server Properties.
  6. Click Virtual Hosts.
  7. Click the IP-based tab in the form.
  8. Click Add under the Virtual host containers table.
  9. Enter a valid IP address in the IP address or hostname column.
  10. Enter a valid port number in the Port column.
  11. Optional: Enter a server name in the Server name column.
  12. Optional: Enter the document root from where the files will be served in the Document root column.
  13. Click Continue.
  14. Click OK.

Mass-dynamic virtual hosting

Use the Mass-dynamic tab to create a dynamic virtual host with a Name-based or IP-based virtual host, or work with canonical names. A canonical name is the actual name of an HTTP Server resource. For example, a canonical name of the HTTP Server is its true name rather than an alias. See directive <UseCanonicalName> for more information.

The dynamic virtual host allows you to dynamically add Web sites (hostnames) by adding directories of content. This approach is based on automatically inserting the IP address and the contents of the Host: header into the pathname of the file that is used to satisfy the request.

The Mass-dynamic tab provides a subset of options that are more complex than those provided by the other tabs. The options include specifying the root directory for serving files, and selecting the root directory for CGI scripts. The availability of these settings are dependent on what server area you are working with.

At the global configuration server area, all mass-dynamic settings are available. These include:

  • Options on how to build self-referencing URL's.
  • Options for the root directory for serving files.
  • Options for the root directory for CGI scripts.

The mass-dynamic settings use strings and substrings to create a dynamic virtual hosts. For example, to create a simple dynamic virtual host, the Root directory for serving files option is defined as /usr/local/apache/vhosts/%0 and Use server name is selected. A request for http://www.ibm.com/directory/file.html returns /usr/local/apache/vhosts/www.ibm.com/directory/file.html.

The string %0 is an interpolate (insert) string of the server name or IP address. The following defines the interpolate string:

Interpolate (insert) strings
%% inserts a %
%p inserts the port number of the virtual host
%N.M inserts (part of) the name

N and M are used to specify substrings of the name. N selects from the period-separated components of the name, and M selects characters within whatever N has selected. M is optional and defaults to zero if it is not present; the period must be present if and only if M is present. The interpretation is as follows:

Substring interpretation
0 the whole name
1 the first part
2 the second part
-1 the last part
-2 the next to last part
2+ the second and all subsequent parts
-2+ the next to last part and all preceding parts
1+ and -1+ the same as 0

For more information on mass-dynamic virtual hosts refer to mod_vhost_alias.