Skip to main content

Load Balancing your Web farm with Apache and mod_proxy_balancer

By October 18, 2013No Comments

In this tutorial we look at load balancing a web server farm with the Apache HTTPD server 2.2 or higher along with and the modules

  • proxy_module
  • proxy_balancer_module

I am using CentOS 6.4 for my servers for this and the HTTPD server has these modules loaded by default if you have not modified the httpd.conf

To keep the configuration simple I will make use of the /etc/httpd/conf.d directory and create a configuration file for load balancing within this directory on my load balancing server. The load balancing server has the web server installed and for simplicity I have disabled the firewall.

ProxyRequests off
 <Proxy balancer://webfarm >
   ProxySet lbmethod=byrequests
<Location /balancer-manager>
 SetHandler balancer-manager
ProxyPass /balancer-manager !
ProxyPass / balancer://webfarm/

This file is saved as lb.conf to the load balancing server in the directory /etc/httpd/conf.d

ProxyRequests off

This turns off the standard proxy feature of

<Proxy balancer://webfarm >

This starts the definition of a proxy balancer, in this case we call it webfarm. The name, though can be anything and does not relate to host or DNS names.. this can be use to load balance  the following requests:

  • HTTP
  • FTP
  • AJP


Add is member servers to out balancer. We add two servers to the farm and represent two wen servers that I have up and running. In reality the servers would have the same web content but in out case have different pages so we can see the load balancing working.

ProxySet lbmethod=byrequests

With ProxySet we can set properties for the balancer. We set the load balancing method here which is at the default byrequests. This could also be set to bytraffic . By requests is simple load balancing looking at the number if requests, by traffic looks at the bytes transmitted.

Setting up up the location for the balancer-manager is option but gives you a status page to visit to see the statistic on load balancing

Finally we use ProxyPass to disable load balancing if we access the manager. The use of the ! negates use of that URL mapping. In the 2nd ProxyPass setting we map the root ( / ) of the current web-server or load balancer to the webfarm. What this means then is that we need to point the DNS entry for our webfarm to the ip address of the balancer and this then will redirect through the the underlying servers we have load balanced.