Virtual Hosts with JBoss AS

"Virtual Hosts" is a method to serve requests for multiple host names - i.e., www.mycompany.com and www.myothercompany.com can both point to a single IP address.

 

In this article you will find some examples of how to set up virtual hosts for different JBoss AS versions.

 


JBoss AS 7

For virtual hosts configuration of JBoss AS 7, see Virtual Hosts with JBoss AS 7.

JBoss AS 5

 

If you want to set up a virtual host for your web app, create or modify the WEB-INF/jboss-web.xml to contain the highlighted line as follows:

 

your-app.war/WEB-INF/jboss-web.xml

<jboss-web>
   <virtual-host>www.mycompany.com</virtual-host>
   <virtual-host>www.myothercompany.com</virtual-host>
</jboss-web>

 

The following example shows a vhost configuration for the jmx-console.war for jboss-5.0.

jbossweb.sar/server.xml

<Server>
   <Service name="jboss.web">

      <!-- A HTTP/1.1 Connector on port 8080 -->
      <Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" 
               connectionTimeout="20000" redirectPort="8443" ></Connector>

      <Engine name="jboss.web" defaultHost="localhost">
...
         <Host name="localhost"> 
...
            <Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
                cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
                transactionManagerObjectName="jboss:service=TransactionManager" ></Valve>
         </Host>

         <Host name="loopback">
            <Alias>loopback-120</Alias>
            <Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve"
                cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager"
                transactionManagerObjectName="jboss:service=TransactionManager" ></Valve>
         </Host>
    </Engine>
  </Service>
</Server>

 

 

jmx-console.war/WEB-INF/jboss-web.xml

<jboss-web>
   <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
      <security-domain>java:/jaas/jmx-console</security-domain>

   -->
   <virtual-host>loopback</virtual-host>
</jboss-web>

 


JBoss 4.0.2

This example shows a vhost configuration for the jmx-console.war for jboss-4.0.2.

 

jbossweb-tomcat55.sar/server.xml

<Server>
   <Service name="jboss.web"
      className="org.jboss.web.tomcat.tc5.StandardService">

      <!-- A HTTP/1.1 Connector on port 8080 -->
      <Connector port="8080" address="${jboss.bind.address}"
         maxThreads="250" strategy="lf" maxHttpHeaderSize="8192"
         minSpareThreads="200" maxSpareThreads="250" emptySessionPath="true" 
         enableLookups="false" redirectPort="8443" acceptCount="100"
         connectionTimeout="20000" disableUploadTimeout="true"></Connector>

      <Engine name="jboss.web" defaultHost="localhost">
...
         <Host name="localhost"
            autoDeploy="false" deployOnStartup="false" deployXML="false">
         </Host>

         <Host name="loopback"
            autoDeploy="false" deployOnStartup="false" deployXML="false">
            <Alias>loopback-120</Alias>
            <Valve className="org.apache.catalina.valves.AccessLogValve"
               prefix="loopback-120-" suffix=".log"
               pattern="common" directory="${jboss.server.home.dir}/log"></Valve>
         </Host>
    </Engine>
  </Service>
</Server>

 

 

jmx-console.war/WEB-INF/jboss-web.xml

<jboss-web>
   <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
      <security-domain>java:/jaas/jmx-console</security-domain>
   -->
   <virtual-host>loopback</virtual-host>
</jboss-web>

 


JBoss 3.2.3

As described in the admin/devl guide, do the following.

 

Step 1: Define the hosts in the jbossweb-tomcat41.sar/META-INF/jboss-service.xml Config attribute fragment:

 

      <attribute name="Config">
         <Server>
            <Service name="JBoss-Tomcat">
               <Engine name="MainEngine" defaultHost="vhost1">
                  <Logger className="org.jboss.web.tomcat.Log4jLogger"
                     verbosityLevel="debug" category="org.jboss.web.localhost.Engine"></Logger>

                  <Host name="vhost1">
                     <Alias>vhost1.starkinternational.com</Alias>

                     <Valve className="org.apache.catalina.valves.AccessLogValve"
                        prefix="vhost1" suffix=".log"
                        pattern="common" directory="${jboss.server.home.dir}/log"></Valve>
                     <Valve className="org.jboss.web.tomcat.security.SecurityAssociationValve"></Valve>
                     <!-- Default context parameters -->
                     <DefaultContext cookies="true" crossContext="true" override="true"></DefaultContext>
                  </Host>

                  <Host name="vhost2">
                     <Alias>vhost2.starkinternational.com</Alias>

                     <!-- Access logger -->
                     <Valve className="org.apache.catalina.valves.AccessLogValve"
                        prefix="vhost2" suffix=".log"
                        pattern="common" directory="${jboss.server.home.dir}/log"></Valve>
                     <Valve className="org.jboss.web.tomcat.security.SecurityAssociationValve"></Valve>
                     <!-- Default context parameters -->
                     <DefaultContext cookies="true" crossContext="true" override="true"></DefaultContext>
                  </Host>
               </Engine>

               <!-- A HTTP/1.1 Connector on port 8080 -->
               <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
                  address="" port="8080" minProcessors="5"
                  maxProcessors="100" enableLookups="true" acceptCount="10" debug="0"
                  connectionTimeout="20000" useURIValidationHack="false"></Connector>
            </Service>
         </server>
      </attribute>

 

Step2: Define the Host to which the web app should be deployed using the WEB-INF/jboss-web.xml descriptor virtual-host element:

 

<jboss-web>
    <!-- Deploy this war to vhost2 -->
   <virtual-host>vhost2.starkinternational.com</virtual-host>
</jboss-web>

 


JBoss 3.2.4

Beginning with 3.2.4RC2 where Tomcat5 is the default web container, the Host settings are in the standard tomcat server.xml file.

jbossweb-tomcat50.sar/server.xml

 

<Server>
  <Service name="jboss.web">

    <!-- A HTTP/1.1 Connector on port 8080 -->
    <Connector port="8080" address="${jboss.bind.address}"
         maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
         enableLookups="false" redirectPort="8443" acceptCount="100"
         connectionTimeout="20000" disableUploadTimeout="true" ></Connector>

    <Engine name="jboss.web" defaultHost="localhost">

      <Logger className="org.jboss.web.tomcat.Log4jLogger"
          verbosityLevel="DEBUG"
          category="org.jboss.web.localhost.Engine"></Logger>

      <Host name="localhost" autoDeploy="false">
...
        <!-- Default context parameters -->
        <DefaultContext cookies="true" crossContext="true" override="true" ></DefaultContext>
      </Host>

      <Host name="vhost1">
         <Alias>vhost1.mydot.com</Alias>
         <Alias>vhost1-alias</Alias>
         <Valve className="org.apache.catalina.valves.AccessLogValve"
            prefix="vhost1-" suffix=".log"
            pattern="common" directory="${jboss.server.home.dir}/log"></Valve>
         <Valve className="org.jboss.web.tomcat.security.SecurityAssociationValve"></Valve>
         <!-- Default context parameters -->
         <DefaultContext cookies="true" crossContext="true" override="true"></DefaultContext>
      </Host>

      <Host name="vhost2">
         <Alias>vhost2.mydot.com</Alias>
         <Alias>vhost2-alias</Alias>
         <Valve className="org.apache.catalina.valves.AccessLogValve"
            prefix="vhost2-" suffix=".log"
            pattern="common" directory="${jboss.server.home.dir}/log"></Valve>
         <Valve className="org.jboss.web.tomcat.security.SecurityAssociationValve"></Valve>
         <!-- Default context parameters -->
         <DefaultContext cookies="true" crossContext="true" override="true"></DefaultContext>
      </Host>
    </Engine>
  </Service>
</Server>

 

Also, a single war can be deployed to mulitple virtual hosts through the jboss-web.xml virtual-host element. To make the jmx-console available on localhost, vhost1 and vhost2, edit the

jmx-console.war/WEB-INF/jboss-web.xml

<jboss-web>
   <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
      <security-domain>java:/jaas/jmx-console</security-domain>
   -->
   <virtual-host>localhost</virtual-host>
   <virtual-host>vhost1.mydot.com</virtual-host>
   <virtual-host>vhost2-alias</virtual-host>
</jboss-web>