Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: How to combine multiple Load Balancer Blocks |
|
Author |
|
apishdad
Joined: 01 Jul 2019 Posts: 44 Location: Canada, Toronto
|
Posted: Tue 23 Jan '24 17:31 Post subject: How to combine multiple Load Balancer Blocks |
|
|
I have a situation where I need to have 2 different applications running on the same domain, but want to combine them into one.
Currently my configuration is as follows, any ideas on how to combine them into one <proxy "balancer ....> block?
Code: |
RewriteCond %{TIME} (.+)
RewriteRule .* - [E=DT:%1,NE]
Header add Set-Cookie "ROUTEID=%{DT}e.%{BALANCER_WORKER_ROUTE}e; path=/; HttpOnly" env=BALANCER_ROUTE_CHANGED
<Proxy "balancer://${COMPUTERNAME}-tomcat">
BalancerMember https://server2:8443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server2
BalancerMember https://server3:8443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server3
BalancerMember https://server4:8443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server4
ProxySet stickysession=ROUTEID scolonpathdelim=On lbmethod=byrequests nofailover=On
</Proxy>
<Proxy "balancer://${COMPUTERNAME}-jboss">
BalancerMember https://server2:443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server2
BalancerMember https://server3:443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server3
BalancerMember https://server4:443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server4
ProxySet stickysession=ROUTEID scolonpathdelim=On lbmethod=byrequests nofailover=On
</Proxy>
ProxyPass "/application1" "balancer://${COMPUTERNAME}-jboss/application1"
ProxyPassReverse "/application1" "balancer://${COMPUTERNAME}-jboss/application1"
ProxyPass "/" "balancer://${COMPUTERNAME}-tomcat/"
ProxyPassReverse "/" "balancer://${COMPUTERNAME}-tomcat/"
|
Mod note: added code tags |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Wed 24 Jan '24 0:14 Post subject: |
|
|
Suggest you try using LocationMatch blocks to select the site paths to be proxied to the one balancer, e.g.
Code: |
<Proxy "balancer://${COMPUTERNAME}_1">
BalancerMember https://server2:8443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server2
BalancerMember https://server3:8443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server3
BalancerMember https://server4:8443 loadfactor=3 max=300 connectiontimeout=300 timeout=600 retry=60 route=server4
ProxySet stickysession=ROUTEID scolonpathdelim=On lbmethod=byrequests nofailover=On
</Proxy>
<LocationMatch ^/$>
ProxyPassMatch balancer://${COMPUTERNAME}_1/$1
ProxyPassReverse balancer://${COMPUTERNAME}_1/$1
ProxyPassReverseCookiePath / /
</LocationMatch>
<LocationMatch ^/(application1|application2)(.*)$>
ProxyPassMatch balancer://${COMPUTERNAME}_1/$1$2
ProxyPassReverse balancer://${COMPUTERNAME}_1/$1$2
ProxyPassReverseCookiePath / /
</LocationMatch>
|
You can use a suitable regex to select multiple paths in the one LocationMatch block, but I've never managed to capture the site root using this approach; hence the two blocks.
Edited: I've added $2 to the second LocationMatch block, which was missed in haste.
I'd also consider putting the "Header add Set-Cookie" directive into the proxy balancer block, since BALANCER_ROUTE_CHANGED gets set dynamically based on the proxy route decision for a given request. It may not be strictly necessary, since response headers get processed late in the request, but logically it makes more sense to me. |
|
Back to top |
|
apishdad
Joined: 01 Jul 2019 Posts: 44 Location: Canada, Toronto
|
Posted: Thu 25 Jan '24 6:59 Post subject: |
|
|
Thanks for replying back,
Just one question after reading your commentary more thoroughly...
Are you implying that if you have 2 different services on 2 different port on the same server such as the situation that I have, then I do need 2 different balancer blocks?
The services are:
JBoss runs on port 8443
Tomcat runs on port 443
Is there a way that I can declare only one balancer block in a way that the port number is dynamically allocated through some sort of a variable or regex? |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Thu 25 Jan '24 13:46 Post subject: |
|
|
My apologies. I should have read your balancer configuration more carefully, and confess I didn't spot the port 8443 vs 443 difference between the two.
I'm not aware of any technique to pass the port number dynamically to the balancer, so believe you will need to stick with two balancer definitions.
Since your balancer configurations are so similar, you could use mod_macro to create them at run time, passing the port through the macro - https://httpd.apache.org/docs/2.4/mod/mod_macro.html |
|
Back to top |
|
|
|
|
|
|