Configuring Apache 2.2 as a Load Balancer

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.

Prerequisites
Review the relevant Apache reference documentation:
Task
  1. Install Apache 2.2 or later on a server in your DMZ.
  2. Secure the server.
    Do not enable proxying until your server is secure.
  3. Enable mod_proxy, mod_proxy_balancer.

    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

  4. On Linux, build Apache with these modules enabled.
  5. Enable additional modules as needed.

    Uncomment the lines for any additional modules for which you need the functionality. For more information about these modules, see the Apache documentation at http://httpd.apache.org/docs/2.2/mod/.

  6. On Windows, use the template below to set up load balancing between your Relay Servers.
    Add the lines below to the Apache Web Server configuration file (httpd.conf). Replace terms in italics with actual values in your environment:
    • Apache_port – Apache server port number
    • Apache_srvr_name – Apache server name
    • host_id – virtual host ID
    • host_port – virtual host port number
    • RS_farm – Relay Server farm ID
    • RS#_IP – IP address or server name for Relay Server #
    • RS#_node – node name for Relay Server #
    • RS#_port – port number for Relay Server #
    • webserver_doc_root – doc root in file system used by Apache Web server

    <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=JSESSIONID
        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.

  7. On Linux, use the template below to set up load balancing between your Relay Servers.
    Add the lines below to the Apache Web Server configuration file (httpd.conf). Replace terms in italics with actual values in your environment:
    • RS_farm – Relay Server farm ID
    • RS#_IP – IP address or server name for Relay Server #
    • RS#_node – node name for Relay Server #
    • RS#_port – port number for Relay Server #
    • RS1#_srvr – server name for Relay Server #

    # 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=JSESSIONID
    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>