Home > Software, System Administration > Multiple web applications with JBoss and Apache

Multiple web applications with JBoss and Apache

 

I’ve been struggling for about a week with JBoss and Apache.JBoss AS 7 logo

 

I admit I am not exactly an expert when it comes to deploy web applications in production environment. This is the first time I tried to deploy more than one web application on the same web / application server using Apache2+ JBoss 7.1.1.

 

I already had one web application deployed…

 

First of all, here’s the Apache site configuration (/etc/apache2/sites-available/mydefaultapp):

 

<VirtualHost *:80>
        ServerName      www.mydefaultapp.it
        DocumentRoot /var/www/mydefaultapp
        <Directory /var/www/mydefaultapp>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SetEnvIf Request_URI "/foto/*" no-jk
        JkMount / ajp13
        JkMount /* ajp13
</VirtualHost>

 

On the other hand, the relevant part of JBoss configuration is inside the standalone.xml configuration file (web subsystem):

 

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
     <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="false" default-web-module="mydefaultapp">
         <alias name="localhost"/>
         <alias name="www.mydefaultapp.it"/>
     </virtual-server>
</subsystem>

 

Finally, I had a “per-war” configuration file named “jboss-web.xml” inside WEB-INF directory of my project. It simply was:

 

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
   <security-domain>java:/jaas/mydefaultapp</security-domain>
   <context-root>/</context-root>
</jboss-web>

 

This…. works! So, in these days another application needed to be deployed and associated to its own dns name (domain). What do I have to do for making my new web app coexist with the old one? Well, first of all I tried to deploy the “new” war… FAIL!

 

INSTALL: Failed to process phase INSTALL of deployment “foo.war” Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.web.deployment.default-host./.realm is already registered

 

Well, actually the “jboss-web.xml” of the second war which I am deploying is the same of “mydefaultapp”, the first application already deployed, except for the security-domain name. I mean, the context-root “/” is duplicate. Indeed the documentation is there to be read! You can have multiple war with the same context root deployed, only if they bind to different “virtual hosts”. So I changed my file to be like so:

 

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
   <security-domain>java:/jaas/secondapp</security-domain>
   <context-root>/</context-root>
   <virtual-host>www.secondapp.com</virtual-host>
</jboss-web>

 

Second try…. broken again! :-(

 

Now the error claims it can’t find “www.secondapp.com” service.

 

Gooooogling around and…. I discover that I need to add the virtual server configuration relative to secondapp to JBoss, that was so obvious, so… here it is:

 

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
   <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="false" default-web-module="mydefaultapp">
      <alias name="localhost"/>
      <alias name="www.mydefaultapp.it"/>
   </virtual-server>
   <virtual-server name="secondApp" enable-welcome-root="false" default-web-module="secondApp">
      <alias name="www.secondapp.com"/>
   </virtual-server>

 

Even that… did not work! JBoss keeps telling me: “hey! I can’t find any http://www.secondapp.com web service.”. But I just created it!

 

After a lot of time spent on looking for examples and specific documentation, and about a thousand test configuration, I found by myself that “virtual-host” value must equal the “virtual-server” name attribute!

 

So it should be, in my case:

<virtual-host>secondApp</virtual-host>

instead of:

<virtual-host>www.secondapp.com</virtual-host>

Obviously, in my production environment, I had to create another Apache2 site configuration (sites-available / sites-enabled) for the “secondApp”, identical to the firstApp’s one except for the ServerName.

 

P.S. : I deliberately didn’t explain how to configure mod_jk in Apache2, there are tons of tutorials on that.

 

About these ads
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: