Java Web Server

Virtual Hosts


Contents / Administrator Docs / Developer Docs / Index / AdminTool Contents

Note: Java Web Server uses the term "virtual hosting" in a slightly different way than other web servers with which you may be familiar. In Java Web Server, virtual hosting only affects document roots and is implemented using the HTTP/1.1. HOST header.

This document has the following sections:

Virtual Hosting with One IP Address

If your machine is set up with a single interface card and IP address, you can configure your system to add additional host names by using the Virtual Hosts Setup page.

When you set up virtual hosting, you register the additional hostnames and document roots with the Java Web Server. Then, when a request addressed to your IP address comes in from across the net, the Java Web Server looks at the Host: header sent along with the request and uses it to serve the right HTML documents to fulfill the request.

For example, your machine's IP address is 127.150.89.77, and you have previously mapped the names zebop and muddy to your IP address in the DNS hosts maps. Then, in the Network Setup page you set up zebop to be your primary host, with the default document root server_root/public_html (as shown in Site Setup).

You then use the Virtual Hosts Setup page to register the additional (or "virtual") host name and document root with the Java Web Server. For example, you register a second hostname as muddy, with the document root server_root/MuddyDocs/public_html.

When an HTTP request comes in to your Java Web Server, it actually points at the IP address 127.150.89.77. However, the Java Web Server knows to read the Host: header that comes along with the request and therefore fulfill the request by serving up the right documents.

For example, if someone on the net connects to http://zebop:8080, the Java Web Server knows to serve up the documents in server_root/public_html. Similarly, if an HTTP request comes in pointing at http://muddy:8080, the Java Web Server knows to fulfill the request with the documents in server_root/MuddyDocs/public_html. Both requests have the same IP address: the Java Web Server knows how to distinguish between them to treat each host as its own separate and "virtual" identity.

Note: This feature works only with browsers that send the Host: header, some older browsers may not.

Using Virtual Hosts as Domain Names

One of the benefits of virtual hosting is that you can take advantage of the abilities of DNS to assign separate domain names to each of your virtual hosts. This makes it possible for each host to be treated as its own individual domain out on the net.

For example, you could set up DNS to map the host zebop to the domain www.mymusic.com, and the host muddy to the domain www.more_music.com. Anyone on the net who connects to http://www.mymusic.com will be served the documents in the directory set up for zebop, (server_root/public_html), and anyone who connects to http://www.more_music.com will be served the documents in the directory set up for muddy (server_root/MuddyDocs/public_html).

Settings

The Virtual Hosts page has the following fields:

Host
The host name as it would appear in the URL that is used to locate the page, should be specified here, for example, zebop or muddy.

Document Root
The primary document directory (for example, server_root/MuddyDocs/public_html) that contains the documents you want to serve for this host.

Note: You cannot setup individual cgi-bin directories for virtual hosts. All CGI scripts must be run from the Java Web Server cgi-bin directory, server_root/cgi-bin.

Procedures

To Add a New Virtual Host:

  1. Click Add.
  2. In the Host field, enter the system name of the host (for example, muddy).
  3. In the Document Root field, enter the absolute or relative pathname of the primary document directory for this host.
  4. Click Save.
Note: In the Document Root field, you can enter either a "relative" pathname, or an absolute pathname.

A relative pathname is entered without a starting slash (for example, MuddyDocs/public_html). Relative pathnames entered without the starting slash (/) are always read "relative" to server_root. So, MuddyDocs/public_html without the starting slash means server_root/MuddyDocs/public_html.

An absolute pathname is entered with the starting slash (for example, /home/erik/docs/public_html). Just like a standard UNIX pathname, it is not resolved relative to server_root but absolutely from the UNIX "root," exactly as it is entered.

To Modify a Virtual Host Entry:

  1. Select the field you want to edit.
  2. Click Modify.
  3. Edit the field as needed.
  4. Click Save.

To Remove a Virtual Host Entry:

  1. Select the entry you want to delete.
  2. Click Remove.
  3. Click Save.

Buttons

To make changes to the Virtual Hosts page and have those settings take affect, use the five buttons at the bottom of the screen. These are: Note: If you Add, Modify, or Remove a host, you must Save before the changes take affect.
Top
java-server-feedback@java.sun.com
Copyright © 1997 Sun Microsystems, Inc.
All Rights Reserved.