Virtual hosts

 

Overview

Appservers provide a default virtual host, localhost:80.

When a servlet request is made, the server name and port number are compared to a list aliases in WebSphere. If no match is 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," explaining why you can create it, but cannot start or stop it.

To configure a virtual host...

Console| Environment | Virtual Hosts

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

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

 

The default virtual host (default_host)

WAS provides a default virtual host (default_host).

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.

If MIME entries are not specified at the Web module level, define MIME object types and their file name extensions. For each needed MIME entry, on the MIME Types page, click New; then, on the settings page for a MIME type, specify a MIME type and extension.

After you configure a virtual host alias or change a configuration, regenerate the Web server plug-in configuration and restart WAS.

 

Modify using wsadmin

To modify virtual host values using wsadmin and Jacl...

set def_host [$AdminConfig getid /VirtualHost:default_host/]

$AdminConfig modify $def_host \
{ \
    { \
        aliases \  
        { \
            { \
                {port 80} \
                {hostname *} \
            } \
            { \
                {port 9080} \
                {hostname *} \
            } \
            { \
                {port 9081} \
                {hostname *} \
            } \
        } \
    } \   
}

$AdminConfig save

 

Example: Creating new virtual hosts using a template

  1. Create a new virtual host template

    cp $WAS_HOME/config/templates/default/virtualhosts.xml $WAS_HOME/config/templates/custom/

  2. Edit and customize the new virtualhostname.xml file.

  3. Use the reset command to recognize new templates...

    $AdminConfig reset

  4. Use the AdminConfig object listTemplates command to list available templates...

    $AdminConfig listTemplates VirtualHost

    To list the new templates, restart DeploymentManager or use the AdminConfig object reset command.

  5. Create a new virtual host using the custom template...

    Using Jacl...

    set cell [$AdminConfig getid /Cell:NetworkDeploymentCell/]
    set vtempl [$AdminConfig listTemplates VirtualHost my_host]
    $AdminConfig createUsingTemplate VirtualHost $cell {{name newVirHost}} $vtempl
    

  6. Save the changes:

    Using Jacl...

    $AdminConfig save
    

    The administrative console does not support the use of custom templates. The new template that you create will not be visible in the administrative console panels.

 

MIME type settings

To configure a Multi-Purpose Internet Mail Extensions (MIME) object type.

To view...

Console | Environment | Virtual Hosts | virtual_host_name | MIME Types | MIME_type.

 

Configuration tab

MIME Type Specifies a MIME type, which can be text, image, or application.

An example value for MIME type is text/html. A default value appears only if you are viewing the configuration for an existing instance.

Extensions Lists file extensions of files that map the MIME type.

Example file extensions for a text/html MIME type include .htm, .html, and .txt. A default value appears only if you are viewing the configuration for an existing instance.