Apache HTTP Server versions 2.2.x provides load balancing tools through two Apache
modules
The two modules are:
The mod_proxy_balancer module provides support of HTTP requests load balancing. The
mod_headers module provides HTTP cookies management needed by the Cookie-based request
processing. For Sessionless request processing, the mod_headers module is not required.
Sessionless requests
The following example shows how to configure Apache 2.2.x to do load balancing for
sessionless requests.
It assumes the architecture illustrated by
Session-bound request processing.
<IfModule mod_proxy.c>
ProxyPass / balancer://GASFarm
<Proxy balancer://GASFarm>
BalancerMember http://GAS1.corporate.com
BalancerMember http://GAS2.corporate.com
</Proxy>
</IfModule>
- These configuration entries can be put at the server level in the
httpd.conf file.
- The ProxyPass instruction tells the module to rewrite all incoming
requests so that they are routed to the GASFarm web farm.
- The <Proxy balancer://GASFarm>...</Proxy> block defines
which are the members of GASFarm web farm.
- The BalancerMember instructions declare two HTTP web server members of
GASFarm web farm: GAS1.corporate.com and
GAS2.corporate.com.
For example, the http://localhost/ws/r/echo URL will be rewritten to
http://GAS1.corporate.com/ws/r/echo, assuming that the GAS1.corporate.com
server has been chosen.
Session-bound requests
The following example shows how to configure Apache 2.2.x to do load balancing for
session-bound
requests. It assumes the architecture illustrated by
Session-bound request processing. The example illustrates
cookie-based request
routing.
<IfModule mod_proxy.c>
ProxyPass / balancer://GASFarm stickysession=GAS_AFFINITY
<Proxy balancer://GASFarm>
BalancerMember http://GAS1.corporate.com route=GAS1
BalancerMember http://GAS2.corporate.com route=GAS2
</Proxy>
</IfModule>
<IfModule mod_headers.c>
Header add Set-Cookie "GAS_AFFINITY=balancer.%{BALANCER_WORKER_ROUTE}e;
path=/; domain=.corporate.com" env=BALANCER_WORKER_ROUTE
</IfModule>
- These configuration entries can be put at the server level in the
httpd.conf file.
- The ProxyPass instruction tells the module to rewrite all incoming
requests so that they are routed to the GASFarm web farm. The
stickysession parameter gives the name of the cookie to use to retrieve
the GAS that holds the session.
- The <Proxy balancer://GASFarm>...</Proxy> block declares
which are the members of GASFarm web farm.
- The BalancerMember instructions declare two HTTP web server members of
the GASFarm web farm: GAS1.corporate.com and
GAS2.corporate.com. The route parameter gives the name
of the route associated with that member. If that route name is found in the request
cookie, then that member will be chosen.
- The Header instruction will set, in the HTTP response, the cookie named
GAS_AFFINITY to value balancer.BALANCER_WORKER_ROUTE. The
BALANCER_WORKER_ROUTE variable is assigned to the route of the
GASFarm member that has be chosen for the current request. Lastly, the
env parameter tells the module to set that cookie only if the
BALANCER_WORKER_ROUTE variable is defined.
For example, the http://localhost/ua/r/gwc-demo URL will be rewritten to
http://GAS1.corporate.com/ua/r/gwc-demo, assuming that the
GAS1.corporate.com server has been chosen.