JBoss 7 Multiple root context web applications

12,802

Solution 1

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/

Solution 2

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.

Share:
12,802

Related videos on Youtube

Fabio B.
Author by

Fabio B.

http://www.linkedin.com/in/fabiobozzo

Updated on September 15, 2022

Comments

  • Fabio B.
    Fabio B. over 1 year

    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?

  • Toni
    Toni about 11 years
    Have you removed the JKMount directive? if you use proxyPass you shouldn't need it. On the other hand, if you don't need the <Directory> directives, remove or comment them. They may interfere with the ProxyPass directive. I've added a simple full configuration example.
  • Toni
    Toni about 11 years
    I've just noticed that I forgot to add a backslash at the end of the address. So, a part of removing the directives you don't use, make sure to add the backslash (I've corrected the example).
  • Fabio B.
    Fabio B. about 11 years
    at least now I can see the login form but static resources can't be found and my form isn't working <link type="text/css" rel="stylesheet" href="/myapp/javax.faces.resource/css/login.css.htm;jsession‌​id=yLqJkKu1h7vG6xAen‌​Jn7TvTp.undefined"> How can I send you a pvt message please?
  • Toni
    Toni about 11 years
    Could you post the new configuration you're using? And about the css, are they in a context different to the application one?
  • natedennis
    natedennis over 9 years
    down voted without a comment. classy im ok with it because the difference between the person that down voted it and I is when this was written, what i said was in fact correct. I was running multiple sites on the same instance mapped with that same configuration. go test it before you down vote it next time.