JBoss virtual hosts
From Oxxus Wiki
JBoss service, as any other web related server, allows for multiple domains to be hosted at same server. This feature, known as virtual domains, requires some additional configuration on JBoss configuration files.
In example below, two domains will be hosted, and configuration files set for them, but there can be as many virtual domains as needed.
Domain names in the example are test.com and test.org. An assumption is made that applications for each of them are developed and archived within war archives, test.com.war and test.org.war. This is not required but is the most common scenario.
Both domains have to be registered and their DNS records set to hosting company's name servers in order to be able to access virtual domains via their domain names. IP address also can be used in testing phase but when it comes to the live one, actual domain names are required.
Prior to beginning, war archives have to be placed in Jboss deployer folder so Jboss can pick it up and deploy upon start-up. Deployer folder is set to /var/jbossX/server/default/deploy/ at our VPS hosting account.
Then, these virtual domains ,as well as any additional ones, will have to be added to Jboss jboss-web.xml file. This has to be defined in every application you archive. Contents are shown below.
In test.com.war WEB-INF/jboss-web.xml:
<jboss-web> <context-root>/test.com</context-root> </jboss-web>
In test.org.war WEB-INF/jboss-web.xml:
<jboss-web> <context-root>/test.org</context-root> </jboss-web>
These settings will be deployed as web roots for virtual domains.
Last step is to define virtual domains at Jboss server.xml file for each domain you'll have, in this example test.com and test.org.
The file needed for configuration, server.xml, is located in Jboss's sar subfolder at foder /var/jboss6/server/default/deploy/jbossweb.sar/.
By default, only localhost is defined within <Host> sections so new virtual domain settings has to be added, just after localhost one is closed, with </Host>.
For test.com:
<Host name="test.com" autoDeploy="false" deployOnStartup="false" deployXML="false"> <Alias>www.test.com</Alias> <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="test.com" suffix=".log" pattern="common" directory="${jboss.server.home.dir}/log"/> <DefaultContext cookies="true" crossContext="true" override="true"/> </Host>
For test.org:
<Host name="test.org" autoDeploy="false" deployOnStartup="false" deployXML="false"> <Alias>www.test.org</Alias> <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="test.org" suffix=".log" pattern="common" directory="${jboss.server.home.dir}/log"/> <DefaultContext cookies="true" crossContext="true" override="true"/> </Host>
Once these definitions are applied and file is saved, Jboss needs to be restarted in order to activate newly added settings.
If any of the applications are to be main web root, using the following settings (for e.g. test.com) will achieve just that in /WEB-INF/jboss-web.xml:
<jboss-web> <context-root>/</context-root> <virtual-host>test.com</virtual-host> </jboss-web>