Configuring Apache as a load balancer

This tutorial will walk you through configuring Apache as a load balancer to direct client requests to a group of PowerServer Web APIs. You will have to configure Apache as a load balancer and use the "Request Counting" load balancer scheduler algorithm and the cookie in order to support sticky sessions.

Step 1: Follow the sections below to install Apache 2.4 (The load balancing feature is available in Apache 2.2 or later).

Step 2: Configure Apache to direct requests to the PowerServer Web APIs group using the "Request Counting" load balancer scheduler algorithm and the cookie.

  1. For Windows Apache, make sure the following lines are NOT commented out in the httpd.conf file.

    mod_proxy, mod_proxy_http, mod_proxy_balancer, mod_lbmethod_byrequests (the "Request Counting" algorithm), and mod_headers (stickyness cookie) must be enabled in order to have the load-balancing ability.

    LoadModule headers_module modules/
    LoadModule status_module modules/
    LoadModule slotmem_shm_module modules/
    LoadModule lbmethod_byrequests_module modules/
    LoadModule proxy_module modules/
    LoadModule proxy_balancer_module modules/
    LoadModule proxy_http_module modules/
  2. Add the following lines to the end of the httpd.conf file.

    The "Header" directive provides load balancing with stickyness using mod_headers.

    The "Max-Age" attribute specifies the number of seconds until the cookie expires. This value must be greater than the session timeout value (which is 3600 seconds by default).

    The "BalancerMember" directive specifies the URL of the server instance in the group.

    The "stickysession" attribute specifies the name of the cookie.

    For more information, refer to

    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; Max-Age=3700; path=/" env=BALANCER_ROUTE_CHANGED
    ProxyRequests Off 
    <Proxy balancer://mycluster> 
    BalancerMember route=server1
    BalancerMember route=server2
    BalancerMember route=server3
    ProxySet stickysession=ROUTEID
    ProxyPass / balancer://mycluster/