To use Apache 2.2 and later as a software load balancer, edit the Apache configuration file to enable mod_proxy and mod_proxy_balancer and set up the load-balancing features.
Uncomment the following lines in the Apache Web Server configuration file (httpd.conf):
# mod_proxy - core module for proxying: LoadModule proxy_module modules/mod_proxy.so # mod_proxy_balancer implements clustering and load balancing: LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
Uncomment the lines for any additional modules for which you need the functionality. See the Apache documentation at http://httpd.apache.org/docs/2.2/mod/.
<VirtualHost host_id:host_port>
ServerName Apache_srvr_name:Apache_port
DocumentRoot webserver_doc_root
# Enable forward proxy
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Enable reverse proxy
ProxyPass / balancer://RS_farm/ stickysession=X-SUP-SESSID
ProxyPassReverse / http://RS1_IP:RS1_port/
ProxyPassReverse / http://RS2_IP:RS2_port
<Proxy balancer://RS_farm>
BalancerMember http://RS1_IP:RS1_port/ route=RS1_node
BalancerMember http://RS2_IP:RS2_port/ route=RS2_node
# Set counting algorithm to more evenly distribute work:
ProxySet lbmethod=byrequests
</Proxy>
# Enable load balancer management
<Location /balancer-manager>
SetHandler balancer-manager
</Location>
<Directory "htdocs">
AllowOverride AuthConfig
</Directory>
</VirtualHost>
Extend the example above to any number of Relay Servers by adding them to the ProxyPassReverse and BalancerMember lists.
# Enable forward proxy
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Proxy balancer://mycluster>
BalancerMember http://RS1_IP:RS1_port/ route=RS1_node loadfactor=5 route=RS1_srvr
BalancerMember http://RS2_IP:RS2_port/ route=RS2_node loadfactor=5 route=RS2_srvr
# Set counting algorithm to more evenly distribute work:
ProxySet lbmethod=byrequests
</Proxy>
# Enable reverse proxy
ProxyPass / balancer://RS_farm/ stickysession=X-SUP-SESSID
ProxyPassReverse / http://RS1_IP:RS1_port
ProxyPassReverse / http://RS2_IP:RS2_port
# Enable load balancer management
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>