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

    Apache Rewrite with proxy_mod_cluster

    koi03

      All

       

      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
          jfclere

          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
            koi03

            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
              mbabacek

              Sure thing Rob, here you go:

               

              Apache HTTP Server load balancer

              mod_cluster.conf:

              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
                  </Directory>
                  ServerAdvertise on
                  UseAlias 1
                  EnableMCPMReceive
                  <Location /mod_cluster_manager>
                    SetHandler mod_cluster-manager
                    # Change it!
                    Require all granted
                 </Location>
              
                </VirtualHost>
              </IfModule>
              

              JBoss AS7x example

              standalone-ha.xml:

                      <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>
                          <virtual-server name="web1" default-web-module="simplecontext-web1">
                              <alias name="web1.rhel7GAx86-64"/>
                          </virtual-server>
                          <virtual-server name="web2" default-web-module="simplecontext-web2">
                              <alias name="web2.rhel7GAx86-64"/>
                          </virtual-server>
                      </subsystem>

              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"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd">
                <virtual-host>web1</virtual-host>
                <context-root>/</context-root>
              </jboss-web>

              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:

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

              mod_cluster_manager.gif

              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
              <html>
              <body>
              <h2>Hello World! Simplecontext Web1!</h2>
              </body>
              </html>
              
              
              curl http://web2.rhel7GAx86-64:6666
              <html>
              <body>
              <h2>Hello World! Simplecontext web2 !</h2>
              </body>
              </html>

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

               

              Cheers

              -K-

              • 4. Re: Apache Rewrite with proxy_mod_cluster
                koi03

                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.