Setting up mod_proxy_balancer

posted by SpringSource on May 25, 2010 03:54 PM

Setting up Apache Web Server and Tomcat Application Server for load balancing using mod_proxy_balancer.

This example uses mod_proxy_balancer as the load balancer. This configuration is useful for applications that are stateless and therefore do not require clustering or sticky-sessions. For more information, you can also check the page:

The example also uses ERS Apache 2.2,  but the configuration is the same except for directory paths using Apache 2.2.

First of all, you will need to load the mod_proxy_balancer module. If you also want to use the Balancer Manager, make sure mod_status is being loaded as well.

LoadModule status_module "/opt/ers40jk/apache2.2/modules/standard/"
LoadModule proxy_balancer_module "/opt/ers40jk/apache2.2/modules/standard/"

Later in the config file, add something like the following to configure the balancer:

<IfModule mod_proxy_balancer.c>
<Location "/balancer-manager">
  SetHandler balancer-manager
  Order deny,allow
  Deny from all
  # Allow from local subnet only
  Allow from 192.168.0
<Proxy balancer://localhost>
  BalancerMember http://localhost:8280/ loadfactor=1
  BalancerMember http://localhost:8380/ loadfactor=2
ProxyPass /lbtest balancer://localhost/lbtest/

Note that this configuration limits the balancer-manager to clients with IP addresses that start with 192.168.0. You'll probably need to modify this as appropriate for your environment.

This example is setup for round robin load balancing where the second BalanceMember processes 2 of every 3 requests. You can adjust this and also the load balancing method based on your needs. Some different load balancing methods mentioned in the doc are byrequests, bytraffic and bybusyness. Additional properties like these can be set using the ProxySet directive as described at

To test this, setup the following directory structure in each of your Tomcat instances (listening for HTTP traffic on ports 8280 and 8380 respectively):

linwin01-516> ls -R webapps/l*

Note: Be sure to make the index.html files unique to each Tomcat instance and directory so you can see the load balancer working for consecutive requests.

For more than 10 years, SpringSource employees have been supporting Apache technologies, with unparalleled experience and commitment to the Apache Software Foundation. More than 400 of the Fortune 500 count on SpringSource to support their mission-critical business applications. Leaders of the Apache Software Foundation, including Board Members, work at SpringSource and dedicate a significant amount of time further developing the Apache Tomcat open source project. Over the last 2 years, 95% of the issues fixed in the Apache Tomcat project were fixed by SpringSource engineers. For more information on how SpringSource can help your enterprise, see the SpringSource website, or call 800/444-1935.