0
votes

I have multiple applications deployed in Tomcat's webapps folder (app1.0, app1.1, app1.2 etc.). When I hit www.example.com:8080/app1.0, the corresponding application appears.

But how to do it on the load-balancing server? For instance, I have a website on which I can click a button (app1.0, app1.1, app1.2 etc.) and an URL pops up like: www.lb.com/app1.0/.../... How to direct to the app based on application version in URL? Use RewriteCond and regex and pass it to ProxyPass? I don't really how to script it, anyone could help? :)

Edit: This is what I done for the 2 apps for 1 Tomcat and 2 apps for 2 Tomcat, but I got 404 sometimes because the Tomcat that has another version has been chosen by the load-balancer.

<VirtualHost *:80>
#Add a http header to explicitly identify the node and be sticky
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED

#Declare the http server pool
<Proxy "balancer://plf">
    BalancerMember "http://worker1.com:8080" route=worker1
    BalancerMember "http://worker2.com:8080" route=worker2
    ProxySet stickysession=ROUTEID
    ProxySet lbmethod=bybusyness
</Proxy>

#Common options
ProxyRequests           Off
ProxyPreserveHost       On

#Declare the redirection for the http requests
ProxyPassMatch        "/app(.*)"     "balancer://plf/app$1"  
ProxyPassReverse      "/app(.*)"     "balancer://plf/app$1"

1

1 Answers

0
votes

This is how I did it:

1) define a balancer proxy:

<Proxy balancer://portalcluster stickysession=JSESSIONID>

    BalancerMember ajp://TOMCATSERVER1:8009 route=TOMCARSERVER1-0
    BalancerMember ajp://TOMCATSERVER2:8009 route=TOMCATSERVER2-100

</Proxy>

2) proxy to it in your VirtualHost:

Listen 443
<Virtualhost *:443>
    ServerName example.com

    Alias /static /var/www/portalstatic

    ProxyPass /static !
    ProxyPass / balancer://portalcluster/
    ProxyPassReverse / balancer://portalcluster/

</Virtualhost>

NB I removed a lot of configuration from these, that are not related to the question (logs, deny clauses, certificate directives, ...). This is just to illustrate the way I did the proxy.

NB2 I did leave the /static trick since this is usually something you will want to do. Static files must stay on the HTTP, and not send them from Tomcat all the time.