JKL Toy Company creates virtual hosts on HTTP Server

This scenario discusses how to create virtual hosts in an IBM® HTTP Server for i Web server.

Scenario

The JKL Toy Company (a fictitious company) wants to serve two domain names from one IP address. This can be done using virtual hosts.

The JKL Web administrator has decided to use the name-based virtual host for HTTP Server JKLTEST. The ISP has configured the Domain Name Server to route requests for JKLINFO to IP address 9.5.61.228, port 78.

Prerequisites

Start the IBM Web Administration for i interface

Access the IBM Web Administration for i from your browser. For information about how to access the Web Administration for i interface, see Starting Web Administration for i.

Set up a name-based virtual host

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.

    Example: JKLTEST

  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.
    Example: 9.5.61.228
    Note: The IP address 9.5.61.288 used in this scenario is associated with JKL Toy Company's IBM i hostname JKLINFO and registered by a Domain Name Server (DNS). You will need to choose a different IP address and hostname. The IBM Web Administration for i interface 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.
  10. Enter a port number in the Port column.

    Example: 78

  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.

    Example: JKLINFO.com

    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.

    Example: /www/jkltest/companyinfo/

    Note: You are specifying a document root using a directory that will be added below in the Set up the virtual host directories section.
  14. Click Continue.
  15. Click OK.

Set up Listen directive for virtual host

  1. Expand Server Properties.
  2. Click General Server Configuration.
  3. Click the General Settings tab in the form.
  4. Click Add under the Server IP addresses and ports to listen on table.
  5. Select the IP address you entered for the virtual host in the IP address column.

    Example: 9.5.61.228

  6. Enter the port number you entered for the virtual host in the Port column.

    Example: 78

  7. Accept Disabled default for FRCA.
  8. Click Continue.
  9. Accept the default values for the remainder of the form.
  10. Click OK.

Set up the virtual host directories

  1. Select the virtual host from the Server area list.
  2. Expand HTTP Tasks and Wizards.
  3. Click Add a Directory to the Web.
  4. Click Next.
  5. Select Static web pages and files.
  6. Click Next.
  7. Enter a directory name for the virtual host in the Name field.

    Example: /www/jkltest/companyinfo/

  8. Click Next.
  9. Enter an alias for the virtual host in the Alias field.

    Example: /companyinfo/

  10. Click Next.
  11. Click Finish.

The document root and directory for the virtual host has been created.

Restart your HTTP Server

Select one of the following methods below:

Manage one server

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.
  4. Click the Stop icon if the server is running.
  5. Click the Start icon.

Manage all servers

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select All Servers from the Server list.
  4. Click the All HTTP Servers tab.
  5. Select your HTTP Server name in the table.

    Example: JKLTEST

  6. Click Stop if the server is running.
  7. Click Start.
Note: If your HTTP Server does not start, see Troubleshooting.

Test your HTTP Server

  1. Start a new Web browser.
  2. Enter http://[virtual_hostname_name]:[port] in the location or URL field.

    Example: http://JKLINFO:78

View your HTTP Server configuration

Your configuration will look similar if you used the given example in this and previous examples.

  1. Click the Manage tab.
  2. Click the HTTP Servers subtab.
  3. Select your HTTP Server from the Server list.

    Example: JKLTEST

  4. Expand Tools.
  5. Click Display Configuration File.
Listen *:1975
Listen 9.5.61.228:78
DocumentRoot /www/jkltest/htdocs
TraceEnable Off
Options -FollowSymLinks 
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{Cookie}n \"%r\" %t" cookie
LogFormat "%{User-agent}i" agent
LogFormat "%{Referer}i -> %U" referer
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log combined
LogMaint logs/access_log 7 0
LogMaint logs/error_log 7 0
SetEnvIf "User-Agent" "Mozilla/2" nokeepalive
SetEnvIf "User-Agent" "JDK/1\.0" force-response-1.0
SetEnvIf "User-Agent" "Java/1\.0" force-response-1.0
SetEnvIf "User-Agent" "RealPlayer 4\.0" force-response-1.0
SetEnvIf "User-Agent" "MSIE 4\.0b2;" nokeepalive
SetEnvIf "User-Agent" "MSIE 4\.0b2;" force-response-1.0
<Directory />
	Require all denied
</Directory>
<Directory /www/jkltest/htdocs>
	Require all granted
</Directory>
<VirtualHost 9.5.61.228:78>
	ServerName JKLINFO.com
	DocumentRoot /www/jkltest/companyinfo/
	<Directory /www/jkltest/companyinfo>
		Require all granted
	</Directory>
	Alias /companyinfo/ /www/jkltest/companyinfo/
</VirtualHost>