+

Search Tips   |   Advanced Search

Virtual hosts

A virtual host is a configuration entity that enables a single host machine to resemble multiple host machines. It maintains a list of Multipurpose Internet Mail Extensions (MIME) types that it processes. We can associate a virtual host to one or more Web modules, but we can associate each web module with one and only one virtual host. Resources associated with one virtual host cannot share data with resources associated with another virtual host, even if the virtual hosts share the same physical machine.

Each virtual host has a logical name and a list of one or more DNS aliases by which it is known. A DNS alias is the TCP/IP hostname and port number used to request the servlet, for example yourHostName:80. When no port number is specified, 80 is assumed.

The virtual host configuration uses wildcard entries with the ports for its virtual host entries.

A client request for a servlet, JavaServer Pages file, or related resource contains a DNS alias and a Uniform Resource Indicator (URI) that is unique to that resource. When a client request for a servlet, JavaServer Pages file, or related resource is received, the DNS alias is compared to the list of all known virtual host groups to locate the correct virtual host, and the URI is compared to the list of all known URI groups to locate the correct URI group. If the virtual host group and URI group are found, the request is sent to the corresponding server group for processing and a response is returned to browser. If a matching virtual host group or URI group is not found, an error is returned to the browser.

A virtual host is not associated with a particular node (machine). It is a configuration, rather than a live object, which is why we can create it, but cannot start or stop it. A default virtual host, named default_host, is automatically configured the first time we start an application server. Unless you specifically want to isolate resources from one another on the same node (physical machine), you probably do not need any virtual hosts in addition to the default host.

The DNS aliases for the default virtual host are configured as *:80 and *:9080, where port 80 is the HTTP server port and port 9080 is the port for the default server's HTTP transport. The default virtual host includes common aliases, such as the machine's IP address, short host name, and fully qualified host name. One of these aliases comprises the first part of the path for accessing a resource such as a servlet. For example, the alias localhost:80 is used in the request http://localhost:80/myServlet.

Add a localhost to the virtual hosts adds the host name and IP address of the localhost machine to the alias table. This allows a remote user to access the administrative console.

Use the administrative console to add or change DNS aliases to use ports other than the default ports. If we do make a change to a DNS alias, we must regenerate the web server plug-in configuration. Use the administrative console to initiate the plug-in regeneration.

We might want to add additional aliases or change the default aliases if:

bprac

When we request a resource, the product tries to map the request to an alias of a defined virtual host. The http://host:port/ portion of the virtual host is not case sensitive, but the URL that follows is case sensitive. The match for the URL must be alphanumerically exact. Different port numbers are treated as different aliases.

For example, the request...

...maps successfully to...

...but not to...

In the latter two cases, these mappings fail because of case sensitivity. The request...

does not map successfully to...

These mappings fail because they are not alphanumerically correct.

Use wildcard entries for aliases by port and specify that all valid host name and address combinations on a particular port map to a particular virtual host.

If we request a resource using an alias that cannot be mapped to an alias of a defined virtual host, we receive a 404 error in the browser that we used to issue the request. A message states that the virtual host could not be found.

Two sets of associations occur for virtual hosts. Application deployment associates an application with a virtual host. Virtual host definitions associate the network address of the machine and the HTTP transport or web server port assignment of the application server with the virtual host. Looking at the flow from the web client request for the snoop servlet, for example, the following actions occur:

  1. The web client asks for the snoop servlet: at web address http://www.some_host.some_company.com:9080/snoop

  2. The some_host machine has the 9080 port assigned to the stand-alone application server, server1.
  3. server1 looks at the virtual host assignments to determine the virtual host that is assigned to the alias some_host.some_company.com:9080.

  4. The application server finds that no explicit alias for that DNS string exists. However, a wild card assignment for host name * at port 9080 does exist. This is a match. The virtual host that defines the match is default_host.

  5. The application server looks at the applications deployed on the default_host and finds the snoop servlet.

  6. The application server serves the application to the web client and the requester is able to use the snoop servlet.

Virtual host Alias Port
default_host * 9080
localhost 9080
my_machine 9080
my_machine.my_company.com 9080
localhost 80

The Application Server looks for a match using the explicit address specified on the web client address. However, it might resolve the match to any other alias that matches the pattern before matching the explicit address. Simply defining an alias first in the list of aliases does not guarantee the search order whenever the product is looking for a matching alias.

A problem can occur if we use the same alias for two different virtual hosts. For example, assume that we installed the default application and the snoop servlet on the default_host. We also have another virtual host called the admin_host. However, we have not installed the default application or the snoop servlet on the admin_host.

Virtual host Alias Port
default_host * 9080
localhost 9080
admin_host * 9060
my_machine.com 9080

Assume that a web client request comes in for http://my_machine.com:9080/snoop.

If the application server matches the request against *:9080, the application is served from the default_host. If the application server matches the request to my.machine.com:9080, the application cannot be found. A 404 error occurs in the browser that issues the request. A message states that the virtual host could not be found.

This problem is the result of not finding the requested application in the first virtual host that has a matching alias. The correct way to code aliases is for the alias name on an incoming request to match only one virtual host in all of our virtual host definitions. If the URL can match more than one virtual host, we can see the problem just described.

  • Configure virtual hosts