Virtual Hosts with JBoss AS 7

JBoss AS 7 configuration of Virtual Hosts differs from previous versions.

Open standalone/configuration/standalone.xml or domain/configuration/domain.xml and search for "virtual".

You'll get to this subsystem:

 

<subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
    <connector name="http" scheme="http" protocol="HTTP/1.1" socket-binding="http"/>
    <virtual-server name="default-host" enable-welcome-root="true">
        <alias name="localhost" />
        <alias name="example.com" />
    </virtual-server>
</subsystem>

 

This is the default host listeming on port 8080, serving ROOT.war at root context "/".

 

To define other virtual hosts with your web app, don't forget to set default-web-module to a name of the web module, which is the name of the war without ".war" extension by default:

 

<subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="virtualServerName">
    <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
    <virtual-server name="virtualServerName" default-web-module="nameOfWarModuleWithoutDotWar">
        <alias name="example.net"/>
        <alias name="example.org"/>
    </virtual-server>
</subsystem>

 

For most recent and authoritative source of configuration options, see the XSD files in JBoss AS 7 sources:

https://github.com/OndraZizka/jboss-as/tree/master/build/src/main/resources/docs/schema

In our case, we are interested in web configuration definition:

https://github.com/OndraZizka/jboss-as/blob/master/build/src/main/resources/docs/schema/jboss-as-web_1_0.xsd

There you can see what everything you can use to configure for the <virtual-host> element.

Documentation for these options may be available at https://docs.jboss.org/author/display/AS7 .

 

Also, per-WAR definition in your.war/WEB-INF/jboss-web.xml still works:

 

<jboss-web>
   <virtual-host>localhost</virtual-host>
   <virtual-host>ondra.zizka.cz</virtual-host>
   <virtual-host>ondrazizka.com</virtual-host>
</jboss-web>

 

Thanks to Marcio Dantas.