4 Replies Latest reply on Aug 3, 2015 11:32 AM by Rob Breault

    Apache Rewrite with proxy_mod_cluster

    Rob Breault Newbie



      I am at a loss for the following.


      The configuration is as follows.


      4 Jboss AS servers hosting 2 applications then 2 Apache 2.4 web servers that do load balancing


      What we had to start


      4 Jboss AS running application1


      1 Apache server with mod_cluster


      application1 is the ROOT context on the 4 jboss AS servers so everything works fine.


      We then deployed Application2 (which isn't default ROOT)


      Built web server 2 and configured the cluster mod


      If I use web02 and connect  to example http://www.test.com/ I get application1 as expected since its root context.


      What I would like to do is on web02 rewrite / to /application2 so that when a user goes to web02.test.com/ they get application2 instead of application1


      Is this possible with mod_rewrite?


      I have tried about every combination with [P] on the rewrite or rewriting to a different host etc and can't see to get the rewire to work.


      Any advice would be awesome.


      So the end result would be


      web01 they get application1


      web02 they get application2


      Both applications are deployed to all 4 JBoss instances with application1 being the ROOT context.


      Also I know application2 is working as if I use http://www.test.com/application2 I get the correct application


      I also use two different DNS so maybe possible using HOST_NAME or SERVER_NAME in the rewrite


      http://web01.test.com/ gets application1 which is ROOT context


      they web02


      http://web02.test.com/ (with rewrite get application2 which context is /application2)


      Thank you

        • 1. Re: Apache Rewrite with proxy_mod_cluster
          Jean-Frederic Clere Master

          Why you don't use 2 virtual-host in AS and have one with application1 as root and the other applications2 as root?

          Then use UseAlias 1 httpd.conf for the mod_cluster configuration and remove all the mod_rewrite stuff.

          • 2. Re: Apache Rewrite with proxy_mod_cluster
            Rob Breault Newbie

            I like that option do you know of a sample configuration or a document that I could follow on the configuration?

            • 3. Re: Apache Rewrite with proxy_mod_cluster
              Michal Karm Babacek Apprentice

              Sure thing Rob, here you go:


              Apache HTTP Server load balancer


              LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
              LoadModule cluster_slotmem_module modules/mod_cluster_slotmem.so
              LoadModule manager_module modules/mod_manager.so
              LoadModule advertise_module modules/mod_advertise.so
              MemManagerFile /tmp/jws-3.0/httpd/cache/mod_cluster
              <IfModule manager_module>
                Listen 6666
                <VirtualHost *:6666>
                  <Directory />
                    # Change it!
                    Require all granted
                  ServerAdvertise on
                  UseAlias 1
                  <Location /mod_cluster_manager>
                    SetHandler mod_cluster-manager
                    # Change it!
                    Require all granted

              JBoss AS7x example


                      <subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" instance-id="workerXXX" 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="true">
                              <alias name="localhost"/>
                              <alias name="example.com"/>
                          <virtual-server name="web1" default-web-module="simplecontext-web1">
                              <alias name="web1.rhel7GAx86-64"/>
                          <virtual-server name="web2" default-web-module="simplecontext-web2">
                              <alias name="web2.rhel7GAx86-64"/>

              The modcluster subsystem is left to its default. The two example deployments have this setting: simplecontext-web1.war/WEB-INF/jboss-web.xml:

              <?xml version="1.0" encoding="UTF-8"?>
              <jboss-web version="6.0" xmlns="http://www.jboss.com/xml/ns/javaee"
                  xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd">

              For your convenience, I attached the two test applications bundled in a zip file.

              When you start Apache HTTP Server and your JBoss AS7 instance, you should see a similar output on the mod_cluster manager console. Please, note that I'm running the setup on a single dev box, having the following in /etc/hosts:

     rhel7GAx86-64 web1.rhel7GAx86-64 web2.rhel7GAx86-64 web1 web2


              Now, you can see that the whole setup works just as you needed, if I understood correctly your requirements:

              curl http://web1.rhel7GAx86-64:6666
              <h2>Hello World! Simplecontext Web1!</h2>
              curl http://web2.rhel7GAx86-64:6666
              <h2>Hello World! Simplecontext web2 !</h2>

              Please, let us know if it worked for you :-)




              • 4. Re: Apache Rewrite with proxy_mod_cluster
                Rob Breault Newbie

                Thank you Michal as this helped a ton. I was able to configure and then use the UseAlias 1 and set the alias's to the URL(host) I wanted in apache config and worked fantastic.