Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Web Server 6.1 Getting Started Guide

Chapter 2
Creating and Using Virtual Servers

A virtual server is a server that uses a unique combination of IP address, port number and host name to identify it. You might have several virtual servers, all of which use the same IP address and port number but are distinguished by their unique host names.

For example, you might have one virtual server called hr.acme.com, and another called mis.acme.com, both of which reside on the same Web server instance, and listen for requests on the same port.

By using virtual servers, you can:

Figure showing an IP address-based virtual server and a Host header-based virtual server.

As the figure above shows, there are two different types of virtual servers. Virtual servers that use a unique IP address and port combination are known as hardware virtual servers. Each web site configured on a hardware virtual server has a single IP address. This means that for each web site that you add, you need a new IP address. Because IP addresses are limited, this places a constraint on the number of virtual servers that you can configure.

The other type of virtual server is the software virtual server. Software virtual servers use an IP address and port combination, and also the contents of an HTTP Host Header (the requested host name) to distinguish one virtual server from another. This enables one machine (with one IP address) to support multiple web sites, each of which is uniquely identified on that machine by its HTTP Host Header. This eliminates the need for many IP addresses.

Sun ONE Web Server 6.1 supports both hardware (IP address-based) and software (HTTP Host Header-based) virtual servers.

When you install Sun ONE Web Server, a default virtual server is created automatically. You can however create other virtual servers and customize them according to your specific needs.

You might have several virtual servers running on a single machine and receive requests for information from hundreds of clients. How would the server know which virtual server should handle which request? Before the server can process a request, it must accept the request via a listen socket, then direct the request to the correct virtual server, based on the value of the IP address or the HTTP Host header. You could manage virtual servers separately or group them together with other “like” servers into a virtual server class.

Before you can create a virtual server, you need two things for it to work:

With this in mind, let’s set out to perform the following tasks:

Let’s say you want to create a virtual server, hr.acme.com. First, you’d need to decide which listen socket it would use. You could use the default listen socket, ls1, that’s created automatically when you install the server or you might want to add a new one. We’ll create a new listen socket in this example.

Create a Listen Socket

To create a listen socket:

  1. Go to the Preferences tab on the Server Manager
  2. Click the Add Listen Socket link.
  3. Specify the ID of the listen socket and the port number it will listen on. Retain the default values listed for the other parameters on the page.
  4. This is shown in the figure below:


    Figure showing the Add Listen Socket interface.

  5. Click OK and then Apply to save and apply your changes.

Next, you need to decide which class you want your virtual server to belong to. Using classes, you can configure similar virtual servers at the same time, so you don’t have to configure each one separately. You could use the default virtual server class, vsclass1, that’s created automatically when you install the server or you could add a new class.

In this example, we will create a new virtual server class, vsclass2.

Create a Virtual Server Class

To add a virtual server class

  1. Access the Virtual Server Class tab in the Server Manager
  2. Click the Add Class link.
  3. Specify the virtual server class name and the document root as an absolute path for the class.

  4. Figure showing the Add Class interface.

  5. Click OK and then Apply to save and apply your changes.

Next, we will create a new virtual server that will use the new listen socket we created, ls2, and will be managed by the virtual server class, vsclass2.

Create a Virtual Server

To create a virtual server:

  1. Access the Virtual Server class tab in the Class Manager
  2. Click the Add Virtual Server link.
  3. Specify the name of the virtual server, its connections, and the URL Hosts. In this example, we specify acme as the URL which clients will use to refer to the server.

  4. Figure showing the Add Virtual Server interface.

  5. Click OK and then Apply to save and apply your changes.

You can configure additional virtual server settings in two ways:

On the Class Manager, the pages are organized by the kind of setting you want to change. Use the Class Manager if you want certain settings to apply to all the virtual servers in the class.

On the Virtual Server Manager, the pages only pertain to one virtual server, so you can see and change all of the settings for a specific server.

Figure showing the Manage Virtual Servers interface.

In the section “Basic Tasks”, we saw that the simplest way to publish content on the site was to put it in the docroot of the server. However, you don’t have to copy everything that you want to publish on your site into the docroot directory. You can also put content into any directory that you have mapped as an additional document directory. Let’s see how this is done.

Create an Additional Document Directory

Let’s say you have a folder called /hr/publish containing pages you want to post to your site.

  1. Access the Virtual Server Class Manager, and click the Content Management tab.
  2. Click Additional Document Directories.
  3. We choose /hr as the URL prefix to map.

  4. Figure showing the Additional Document Directories interface.

  5. Type /hr/publish as the filesystem directory to map those URLs to.
  6. Click OK.

You can now type http://acme/hr in a browser window to access the content you’ve mapped.

All the virtual servers in a virtual server class, by default, have the same document root. This is probably not want you need.

To explain, let’s say you have two virtual servers hr.acme.com and mis.acme.com belonging to the same virtual server class. When a user types http://hr.acme.com on a browser, you probably want them to be taken to a docroot that contains HR information, say /acme/hr. Similarly, when users type http://mis.acme.com on a browser, you want them to go to the MIS site, which has its docroot at say, /acme/mis. You need to configure the docroot for each virtual server individually to achieve this.

Change the Document Root of a Virtual Server

To change the document root of a virtual server:

  1. Access the virtual server manager interface of the virtual server you want to configure, say acme.
  2. Click the Settings link.

  3. Figure showing the Settings page of the Virtual Server Manager.

  4. Edit the path that appears next to the Document Root field setting to point to a new document root.
  5. Click OK.

You can now configure your virtual servers in many other ways to provide differentiated services to different sets of end users, based on specific needs. The rest of this guide demonstrates some of the more common tasks:



Previous      Contents      Index      Next     


Copyright 2003 Sun Microsystems, Inc. All rights reserved.