||
Skip to end of metadata
Go to start of metadata

Virtual host support is an in-built feature of Apache Tomcat that allows you to deploy multiple domains in a single Tomcat server instance. This feature allows the super tenant of your Application Server to deploy web applications with different domain names, which are all hosted with the same ip address. Previous releases of WSO2 Application Server loads web applications to the <AS_HOME>/repository/deployment/server/webapps/ directory. With the new feature in WSO2 AS 5.3.0, there will be a separate folder in the <AS_HOME>/repository/deployment/server/ directory, which corresponds to each host domain created by the super tenant.

Note that virtual hosts can only be created and used by the super tenant. All other users will be allowed to deploy web applications to the default host configured for the product.

See the following topics for instructions: 

Defining virtual hosts for the server

To enable virtual host support and to add new hosts in WSO2 AS:

  1. All the required hosts for your server should be added to the <AS_HOME>/repository/conf/tomcat/catalina-server.xml file as explained below.

    • The catalina-server.xml file comes with the following host enabled by default:

      <Host name="localhost" unpackWARs="true" deployOnStartup="false" autoDeploy="false" appBase="${carbon.home}/
      repository/deployment/server/webapps">
                            ......
      </Host>

      The "host name" attribute specifies the domain name while the “appBase” attribute defines the location that stores the web apps. Note that the "appBase" must be located inside the <AS_HOME>/repository/deployment/server/ folderIn the above example, the default domain name is set to “localhost” and the location of web apps is the "webapps" folder.

    • You can add a new hostname with a new appBase location by adding the following to the catalina-server.xml file:

      <Host name="www.vhost.com" unpackWARs="true" deployOnStartup="false" autoDeploy="false" appBase="${carbon.home}/repository/deployment/server/vhost/">
                         ......
      </Host>
  2. Setup the DNS configuration by mapping the new host name to the preferred IP address as shown below. If you are testing locally, the "hosts" file is located in the /etc/hosts folder for linux. In a production environment, the DNS server should be updated with the domain names accordingly.

    <your-ip-address>        <host-name>

    (eg:  10.100.5.86   www.vhost.com)

Deploying applications in virtual hosts

The virtual hosts for your server are now configured and you can start adding web applications to any appBase location. Note that this enables you to deploy web applications with the same name into different appBases. Web apps can be added to the product in two ways:

  • Simply, copy the WAR file into the relevant appBase location (e.g.: add example.war file to <PRODUCT_HOME>/repository/deployment/server/vhost). When you start WSO2 AS, the web application (example.war) will be deployed and can be accessed through the following address: http://www.vhost.com:9763/<webapp-name>. Note that if you change the default offset value (in the <PRODUCT_HOME>/repository/conf/carbon.xml file), the port number should get updated accordingly. 
  • Use the management console of the product as shown below. You can select the host name when you add a web app from the UI.

    See the topic on deploying applications in AS for instructions on using the management console. 

Virtual hosts in a clustered deployment:

If you have enabled deployment synchronization support in an environment of AS clusters, the web applications that you add to any appBase location in the manager node will not be committed from the manager node to the svn repo. Therefore, the appBase locations of all the virtual hosts will also follow the same behaviour as the default “webapps” directory. For depsync support to work in a worker/manager setup, all the nodes should have a similar configuration in the catalina-server.xml file with the relevant host entries.

Example: Manager node and a worker node with depsync enabled in a cluster.

  1. Consider that a manager node has a new host entry in addition to the default entry as follows:

    <Host name="www.vhost.com" unpackWARs="true" deployOnStartup="false" autoDeploy="false" appBase="${carbon.home}/repository/deployment/server/vhost/">
                       ......
    </Host>
  2. If the manager node deploys a webapp under the newly added host, the webapp will unpacked in the <PRODUCT_HOME>/repository/deployment/server/vhost/ location.

  3. Due to the depsync effect, the .war file in the above location will be synced to the same location of the worker node. For that webapp to deploy properly and to be invoked via the same host name, both the worker and manager nodes should follow the same configuration when adding Host entries to the catalina-server.xml file.
  • No labels