skip to Main Content

We want to use Apache load balance to spread the load over several servers. We plan to do many http://load_balancer:port/app_name redirects on Apache LB e.g:

http://load_balancer:port/app1 —> Apache LB —> http://server1:port1, http://server2:port1

http://load_balancer:port/app2 —> Apache LB —> http://server1:port2, http://server2:port2
….

For Apache LB configuration file as below, when we use http://load_balancer:port in web browser then Apache LB works as expected.

How to rewrite the configuration so that you can enter http://load_balancer:port/app in web browser?

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy "balancer://mycluster">
    BalancerMember "http://server1:port" route=1 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    BalancerMember "http://server2:port" route=2 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    ProxySet stickysession=ROUTEID
</Proxy>

<Proxy "balancer://myws">
    BalancerMember "ws://http://server1:port" route=1 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    BalancerMember "ws://http://server2:port" route=2 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
    ProxySet stickysession=ROUTEID
</Proxy>

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) balancer://myws/$1 [P,L]

RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*) balancer://mycluster/$1 [P,L]

Second configuration

We used the hint as below for the proxy flag. Apache LoadBalancer worked fine for "http://load_balancer:port/". My configuration file:

ProxyPass "/" "balancer://mycluster/" stickysession=JSESSIONID|jsessionid scolonpathdelim=On 
<Proxy "balancer://mycluster">
    BalancerMember "http://server1:8727" route=1
    BalancerMember "http://server2:8193" route=2
</Proxy>

When we changed the configuration to ProxyPass "/test" to refer to "http://load_balancer:port/test" from the web browser, there were errors (404) in the access.log file:

  • GET /test/ HTTP/1.1 200 2375
  • GET /static/css/app.77ac3251.css HTTP/1.1 404 196

2

Answers


  1. Chosen as BEST ANSWER

    We wrote the configuration as below and it works as expected:

    <Proxy balancer://test.cl>
      Header add Set-Cookie "test.ROUTEID=ROUTE.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
      BalancerMember  http://server1:8727 route=test_00 keepalive=On connectiontimeout=5 retry=180
      BalancerMember  http://server2:9393 route=test_10 keepalive=On connectiontimeout=5 retry=180
      ProxySet lbmethod=bybusyness stickysession=ROUTEID
    </Proxy>
    <Location /test>
     ProxyPreserveHost On
      ProxyPass         balancer://test.cl
      ProxyPassReverse  balancer://test.cl
    </Location>
    

  2. You can use apache proxy pass instead of a rewriterule with proxy flag. You can find all the detail about the configuration on the official documentation: https://httpd.apache.org/docs/2.4/mod/mod_proxy_balancer.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search