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) and configure Apache as a reverse proxy server.

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/mod_headers.so
    LoadModule status_module modules/mod_status.so
    LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
    LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    
  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 https://httpd.apache.org/docs/2.4/mod/mod_proxy_balancer.html.

    <VirtualHost *:8080>
                    ProxyPreserveHost On
                    Proxyrequests off
                    SetEnv force-proxy-request-1.0.1
                    SetEnv proxy-nokeepalive 1
                    ErrorLog logs/ps-error.log
                    CustomLog logs/ps-access.log common
    <Proxy *>
                    Require all granted
    </Proxy>
    ProxyPass / balancer://mycluster/
    ProxyPassReverse / balancer://mycluster/
    </VirtualHost>
    
    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; Max-Age=3700; path=/" env=BALANCER_ROUTE_CHANGED
    
    <Proxy balancer://mycluster> 
    BalancerMember https://172.16.100.34:6000 route=server1
    BalancerMember https://172.16.100.35:6000 route=server2
    BalancerMember https://172.16.100.36:6000 route=server3
    ProxySet stickysession=ROUTEID
    </Proxy>