14 Replies Latest reply on Oct 28, 2014 4:23 AM by Jean-Frederic Clere

    Routing request based on context path

    Srinivas S Newbie

      Hi friends,

       

      I configured mod_cluster with tomact7 and Apache2. I have 2 issues:

       

      1) How to route request to tomcats based on context path. How to achieve this with mod_cluster?

          ex:-  http://localhost/Myapp - tomcat1

                  http://localhost/Yourapp - tomcat2

        

        Is the below configuration in httpd.conf still works with mod_cluster and is it the only and correct way ?

      JkMount  /Myapp/* tomcat1

      JkMount  /Yourapp/* tomcat2

       

      2) Enable and Disable context

         enabling and disabing  examples, manager etc  context's are working, but enabing and disabling our application is not working. Any configuration is required?

       

       

      Thanks,

      Srikanth

        • 1. Re: Routing request based on context path
          Jean-Frederic Clere Master

          1) If you deploy Myapp on tomcat1 and Yourapp on tomcat2 mod_cluster doesn't need any configuration.

          2) That should work... The handling of webapp doesn't depend on the webapp.

          • 2. Re: Routing request based on context path
            Srinivas S Newbie

            Thanks.

             

             

            2) Why disable context is not working, please let me know is anything wrong in my setup?

             

             

            #mod_cluster's modules

            LoadModule slotmem_module modules/mod_slotmem.so

            LoadModule manager_module modules/mod_manager.so

            LoadModule proxy_cluster_module modules/mod_proxy_cluster.so

            LoadModule advertise_module modules/mod_advertise.so

             

             

             

             

            #configure listener

            Listen x.x.x.x:9999

             

             

            <VirtualHost x.x.x.x:9999>

            <Location /mod_cluster-manager>

              SetHandler mod_cluster-manager

                    Order deny,allow

                    #Deny from all

                    Allow from x.x.x.x

                </Location>

             

             

                KeepAliveTimeout 60

                MaxKeepAliveRequests 0

                EnableMCPMReceive

              

                ManagerBalancerName mod_cluster-manager

                ServerAdvertise On

                AllowDisplay On

              

            </VirtualHost>

             

               ProxyPass / balancer://mod_cluster-manager

             

             

            @Tomcat

            <!-- Listener for mod_cluster -->

              <Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" proxyList="x.x.x.x:9999" />

              <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">

             

             

            Thanks,

            Srinivas

            • 3. Re: Routing request based on context path
              Jean-Frederic Clere Master

              ProxyPass / balancer://mod_cluster-manager that is why the disable context isn't working...

              • 4. Re: Routing request based on context path
                Srinivas S Newbie

                Thanks Jean for quick response.

                 

                I have noticed the context is getting disabled but every time after disabling from mod_cluster manager, need to clean the browser. Is it due to cookies? Is their any configuration/flag to avoid this?

                 

                Regards,

                Srinivas

                • 5. Re: Routing request based on context path
                  Jean-Frederic Clere Master

                  I don't understand... are you on the mod_cluster manager page? What is wrong?

                  • 6. Re: Routing request based on context path
                    Srinivas S Newbie

                    Jean, Please find the details:

                     

                    1) Accessed application which is on some node and I'am on some page.

                    2) Opened mod_cluster-manger and disabled the context.

                    3) And went back to the same page (step 1) accessed some links and links are opening even after disabling context.

                    4) I have done browser cleaning after that no pages are accessed as expected getting Not Found page.

                     

                    So why I need to clean the browser after disabling context it should straight away show Not Found page?.

                     

                     

                    Regards,

                    Srikanth

                    • 7. Re: Routing request based on context path
                      Jean-Frederic Clere Master

                      I can't tell what is wrong but my guess is that the browser is caching the content of links. Check the access_log to see if you have a request going to httpd.

                      • 8. Re: Routing request based on context path
                        Srinivas S Newbie

                        Thanks Jean.  I will investigate this further.

                         

                          Is there a possibility in mod_cluster that context based routing like below is possible?. My requirement is not to send few requests to one server, means deploying two different applications in  two different tomcats which has same context name like MyApp.  If we are not routing based on context path the request is go to another tomcat which doesn't have that service. With load balancing we use to do the below:

                         

                        Load Balancing

                        JkMount  /Myapp/service/* loadbalncer1

                        JkMount  /Myapp/*  loadbalncer2

                         

                        worker.loadbalncer1.type=lb

                        worker.loadbalncer1.balanced_workers=tomcat1

                         

                        worker.loadbalncer2.type=lb

                        worker.loadbalncer2.balanced_workers=tomcat2

                         

                        Requirement

                          /Myapp/service/* - tomcat1

                          /Myapp/ - tomcat2

                         

                         

                         

                        Thanks,

                        Srinivas

                        • 9. Re: Routing request based on context path
                          Jean-Frederic Clere Master

                          Your example doesn't even do load-balancing....

                           

                          To do something like that with mod_cluster doesn't make sense.

                           

                          You can use ProxyPass /path1 balancer1 and ProxyPass /path2 balancer2 and get different balancer name in each tomcat.

                          • 10. Re: Routing request based on context path
                            Srinivas S Newbie

                            Jean,

                             

                            I have done the following, but no luck

                             

                            On Webserver

                            ProxyPass /restServiceBalancer http://10.10.10.18/test/restservice

                            ProxyPass /webBalancer http://10.10.10.18/test/page

                             

                            On AppServer

                            tomcat1:

                            <Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener"

                              proxyList="10.10.10.18:9999" excludedContexts="ROOT" balancer="restServiceBalancer"/>

                             

                            tomcat2:

                            <Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener"

                              proxyList="10.10.10.18:9999" excludedContexts="ROOT" balancer="webBalancer"/>

                             

                            didn't find any thing logs except this

                            [Fri Oct 17 07:40:23 2014] [warn] ENABLE: context /test is in balancer webBalancer and restServiceBalancer

                             

                            Regards,

                            Srinivas

                            • 11. Re: Routing request based on context path
                              Radoslav Husar Master

                              Not sure if this

                              3) And went back to the same page (step 1) accessed some links and links are opening even after disabling context.

                              is still a concern but disabling means that it won't accept requests without sessionid (= new requests). It will handle the existing ones.

                              • 12. Re: Routing request based on context path
                                Srinivas S Newbie

                                Yes Husar.  I observed that.

                                 

                                But I need to route request to different tomcats based on url for that tried below configuration, but it is not working.

                                On Webserver

                                ProxyPass /restServiceBalancer http://10.10.10.18/test/restservice

                                ProxyPass /webBalancer http://10.10.10.18/test/page

                                 

                                On AppServer

                                tomcat1:

                                <Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener"

                                  proxyList="10.10.10.18:9999" excludedContexts="ROOT" balancer="restServiceBalancer"/>

                                 

                                tomcat2:

                                <Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener"

                                  proxyList="10.10.10.18:9999" excludedContexts="ROOT" balancer="webBalancer"/>

                                 

                                Thanks,

                                Srinivas

                                • 13. Re: Routing request based on context path
                                  Srinivas S Newbie

                                  Hi All,

                                   

                                  Please find the configuration and let me know if there is anything wrong in my configuration. Still facing the same issue.

                                   

                                  #mod_cluster's modules

                                  LoadModule slotmem_module modules/mod_slotmem.so

                                  LoadModule manager_module modules/mod_manager.so

                                  LoadModule proxy_cluster_module modules/mod_proxy_cluster.so

                                  LoadModule advertise_module modules/mod_advertise.so

                                   

                                   

                                  #configure listener

                                  Listen 10.10.10.10:9999

                                  #DocumetRoot /var/www

                                   

                                   

                                  <VirtualHost 10.10.10.10:80>

                                   

                                   

                                     <Directory />

                                    Order deny,allow

                                    #Deny from all

                                          Allow from 10.10.10.10

                                     </Directory>

                                     <Location /mc>

                                    SetHandler mod_cluster-manager

                                          Order deny,allow

                                    #Deny from all

                                          Allow from 10.10.10.10

                                     </Location>

                                   

                                   

                                  </VirtualHost>

                                   

                                   

                                  <VirtualHost 10.10.10.10:9999>

                                    <Directory />

                                    Order deny,allow

                                    #Deny from all

                                          Allow from 10.10.10.10

                                     </Directory>

                                     

                                      ProxyRequests On

                                      ProxyVia On

                                      ErrorLog logs/application_error.log

                                      LogLevel debug

                                      KeepAliveTimeout 120

                                      MaxKeepAliveRequests 0

                                      EnableMCPMReceive

                                      #CreateBalancers 1

                                     

                                      #ManagerBalancerName mod_cluster-manager

                                      ServerAdvertise On

                                      AllowDisplay On

                                      ProxyPass /webBalancer http://10.10.10.10/test/js

                                      ProxyPass /restServiceBalancer http://10.10.10.10/test/page

                                   

                                  </VirtualHost>

                                   

                                  <Proxy balancer://webBalancer>

                                       Order deny,allow

                                       Allow from all

                                       BalancerMember http://10.10.10.10:8080 route=tomcat1

                                  </Proxy>

                                  <Proxy balancer://restServiceBalancer>

                                       Order deny,allow

                                       Allow from all

                                       BalancerMember http://10.10.10.10:9090 route=tomcat2

                                  </Proxy>

                                   

                                   

                                  Thanks,

                                  Srinivas

                                  • 14. Re: Routing request based on context path
                                    Jean-Frederic Clere Master

                                    ProxyPass /webBalancer http://10.10.10.10/test/js

                                    ProxyPass /restServiceBalancer http://10.10.10.10/test/page

                                     

                                    That looks fishy...  The tomcat are probably on port 8080 and 9090.

                                    Additionally that looks like a static configuration without a balancer you don't need mod_cluster nor mod_balancer for that.

                                     

                                    A simple ProxyPass should do the work.

                                    1 of 1 people found this helpful