Buscar este blog

lunes, 15 de agosto de 2016

JBoss - Virtual Servers - Mod_cluster

In JBoss, a virtual server is like a virtual host in apache (httpd). There is always a default virtual server that handles all requests received by the server. So, for each request this is what can happend:
  1. If the request points to the root context ("/"), you get the default welcome application. In this case the ROOT.war
  2. If the request points to a valid context (i.e, the context of a deployed web app), you get the response of this web app.
  3. If the request points to a invalid context, you get a 404

Besides the default virtual server, you can also define your own, by specifying a group of alias (domains) which will be handled in this virtual server.

For example, I have two web apps, /app1 and /app2 deployed, each one in its own context, among other webapps (/app3, /app4, etc.). The absolute URL would by:
  • app1: https://domain1/app1
  • app2: https://domain2/app2
  • app3: https://domain3/app3
  • app4: https://domain4/apps
There is a apache front-end configured with mod cluster. Each domain is a apache virtual host with forward the requests to the JBoss backends (a server cluster).

Now, I want to reconfigure this situation in order to get the following URLs:
  • app1: https://myCommonDomain/
  • app2: https://myCommonDomain/app2
  • app3: https://domain3/app3
  • app4: https://domain4/apps
So, app1 and app2 will be in the same domain, and app1 will be the root context of this domain. In this way, a user will think that both applications are just the same. In other way, I´m merging two web apps in one.

JBoss configuration

The first step is to create a new virtual server in JBoss, in the web subsystem:
<subsystem xmlns="urn:jboss:domain:web:1.5"
 default-virtual-server="default-host" native="false">
 <configuration>
  <jsp-configuration development="true"
   check-interval="2000" />
 </configuration>
 <connector name="http" protocol="HTTP/1.1" scheme="http"
  socket-binding="http" />
 <connector name="ajp" protocol="AJP/1.3" scheme="http"
  socket-binding="ajp" />
 <virtual-server name="default-host"
  enable-welcome-root="true">
  <alias name="localhost" />
  <alias name="example.com" />
 </virtual-server>
 <virtual-server name="myNewVirtualServer" default-web-module="app1.war">
  <alias name="myCommonDomain"/>
 </virtual-server>
</subsystem>

I created a virtual server named myNewVirtualServer, which default root will be app1.war (this is de runtime name of the deployment). This virtual server will be "listening" in myCommonDomain.

Web apps configuration

Inside app1 and app2, you need to include a jboss-web.xml file. In this file, each application declares its root context and references the virtual server created before.

jboss-web.xml in app1.war:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
 <context-root>/</context-root>
 <virtual-host>myNewVirtualServer</virtual-host>
</jboss-web>

jboss-web.xml in app2.war:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
 <context-root>/app2</context-root>
 <virtual-host>myNewVirtualServer</virtual-host>
</jboss-web>

Web apps configuration

Finally, you need to declare a new apache virtual host for this domain.
<VirtualHost *:443> 
 ServerName myCommonDomain
 (...) 
</VirtualHost>


No hay comentarios:

Publicar un comentario