JavaServer

Virtual Hosts


Documentation / Administrator Docs / Developer Docs / Index / Administration Contents

This document has the following sections:

The virtual hosting feature of the JavaServer can be set up in one of two basic ways. These are:

To assign a virtual host you must first determine which situation applies to you.

NOTE: In order to properly use the virtual hosting feature of the the JavaServer, you must have already set up your network to recognize the host and domain names you want to define. If you have not previously done this configuration in your DNS host maps, setting virtual hosting in the JavaServer will not work.

NOTE: In some cases, your system can have multiple interface cards, each with a number of hosts, and all can be mapped to a single IP Address. But this is for advanced users and beyond the scope of this document.

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 JavaServer. Then, when a request addressed to your IP address comes in from across the net, the JavaServer looks at the 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 Basic Setup page you set up zebop to be your primary host, with the default document root server_root/public_html.

You then use the Virtual Hosts Setup page to register the additional (or "virtual") host name and document root with the JavaServer. 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 JavaServer, it actually comes in pointing at the IP address 127.150.89.77. However, the JavaServer knows to read the header that comes alone 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 JavaServer knows to serve up the documents in server_root/public_html. Similarly, if an HTTP request comes in pointing at http://muddy:8080, the JavaServer knows to fulfill the request with the documents in server_root/MuddyDocs/public_html. Both requests have the same IP address: the JavaServer knows how to distinguish between them to treat each host as its own separate and "virtual" identity.

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).

Virtual Hosting with Two IP Addresses

NOTE: In order to set up more than one IP Address on your machine, you must install a second interface card. To do this, follow the instruction manual for your machine.

Once you have properly installed the cards needed to assign a second IP Address to your machine, setting up virtual hosts works exactly the same for each IP as described above. For more information, see Virtual Hosting with One IP Address.

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.

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