Fabio B.
Fabio B.

Reputation: 9400

JBoss 7 Multiple root context web applications

I need to configure two websites: www.foo.com and www.bar.net on my Apache2+ JBoss7.1 environment.

Apache sites configuration example (they're similar each other, except for site name) :

<VirtualHost *:80>
        ServerAdmin     [email protected]
        ServerName      www.foo.com

        DocumentRoot /var/www/foo
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/foo>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                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 "/photos/*" no-jk
        JkMount / ajp13
        JkMount /* ajp13

</VirtualHost>

In JBoss standalone.xml I have:

<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="bar">
                <alias name="localhost"/>
                <alias name="www.bar.net"/>
            </virtual-server>
            <virtual-server name="foo" enable-welcome-root="false" default-web-module="foo">
                <alias name="www.foo.com"/>
            </virtual-server>
        </subsystem>

While both apps have jboss-web.xml:

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

Deploying foo.war results in:

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

What's the right configuration? Where is the error?

Upvotes: 3

Views: 13192

Answers (3)

natedennis
natedennis

Reputation: 117

actually the way he had it is fine. no need for using proxy if he doesn't want. The missing piece to the original config is that he never mentioned that alias in the jboss-web.xml.

<jboss-web>
   <security-domain>java:/jaas/foo</security-domain>
   <context-root>/</context-root>
   <virtual-host>www.foo.com</virtual-host>
</jboss-web>

and in the second app

<jboss-web>
   <security-domain>java:/jaas/foo</security-domain>
   <context-root>/</context-root>
   <virtual-host>www.bar.net</virtual-host>
</jboss-web>

and get rid of that default-web-module tag. you are creating a paradox with that mess. you either go to one or the other.. not both. that is for when you don't have the alias mapped.

Upvotes: 0

Fabio B.
Fabio B.

Reputation: 9400

It was just enough to add foo to my configuration, now working good with mod_jk. I blogged about it: http://fabiobozzo.wordpress.com/2013/02/25/multiple-web-applications-with-jboss-and-apache/

Upvotes: 0

Toni
Toni

Reputation: 1381

I think that the problem is that you've defined the same context root for the two applications. You can't have two applications with the same context root at the sametime. One possible solution would be to define a different context for each application (/foo and /bar respectively), and use the ProxyPass directive in each Apache virtualhost.

<VirtualHost *:80>
        ServerAdmin     [email protected]
        ServerName      www.foo.com
        ...
        ProxyPass         /     http://yourjbossserver:port/foo/
        ProxyPassReverse  /     http://yourjbossserver:port/foo/
</VirtualHost *:80>

<VirtualHost *:80>
        ServerAdmin     [email protected]
        ServerName      www.bar.com
        ...
        ProxyPass         /     http://yourjbossserver:port/bar/
        ProxyPassReverse  /     http://yourjbossserver:port/bar/
</VirtualHost *:80>

This way you could access your applications directly through the addresses: www.bar.com and www.foo.com, respectively. (Notice that if you have an Apache acting as a proxy, and using it's own virtualhosts, there is no need to define JBoss virtualhost).

A simple but complete example would be (in this case I've configured the jboss jmx-console, running in the same machine as the apache, to be accessible from www.foo.com):

<VirtualHost *:80>
    ServerName www.foo.com
    ProxyPass         /     http://localhost:8080/jmx-console/
    ProxyPassReverse  /     http://localhost:8080/jmx-console/
</VirtualHost>

Notice that you need to add a backslash at the end of the address.

Upvotes: 2

Related Questions