Apache HTTP Server as a Simple Reverse‑Proxy Load Balancer with mod_proxy_balancer
Learn the minimal Apache 2.4 setup needed to load‑balance HTTP traffic using mod_proxy_balancer, including configuration, trust boundaries, and operational checks.
15 Sept 2026, 06:53 UTC

Requirements
\nTo use Apache HTTP Server as a reverse‑proxy load balancer you need:
\n- \n
- Apache 2.4 or newer \n
- Modules
mod_proxy,mod_proxy_balancer, and a load‑balancing method such asmod_lb>mod_lbmethod_byrequests(alternatives:bytraffic,bybusyness) \n - Optionally
mod_sslif you want TLS termination at the front‑end \n - Network reachability between the Apache instance and each backend server \n
Smallest Suitable Design
\nThe minimal configuration consists of a single Apache listener that forwards all requests to a balancer defined with two backend workers.
\n# Listen on plain HTTP; change to 443 and add SSL directives if TLS termination is needed\nListen 80\n\n\n ProxyPreserveHost On\n ProxyPass / balancer://mycluster/ lbmethod=byrequests\n ProxyPassReverse / balancer://mycluster/\n\n # Balancer definition\n \n BalancerMember http://10.0.1.11:8080\n BalancerMember http://10.0.1.12:8080\n ProxySet lbmethod=byrequests\n \n\n # Optional: expose balancer‑manager for monitoring (restrict to trusted IPs)\n \n SetHandler balancer-manager\n Require ip 192.168.0.0/16\n \n\n\nThis setup uses the byrequests method, which distributes incoming requests based on the number of requests each worker has handled.
Trust and Data Boundaries
\nThe Apache front‑end is the trust boundary: it terminates the client TCP connection, validates the HTTP request line and headers, and then builds a sanitized proxied request to send to the backend. The backend sees only the proxied request and should not rely on client‑provided headers such as X‑Forwarded‑For unless you explicitly enable and trust them (e.g., with ProxyPreserveHost On or custom RequestHeader directives).
Operational Checks
\nEnable monitoring to verify health and traffic distribution:
\n- \n
- Load
mod_statusand access the balancer‑manager UI athttp://apache-host/balancer-managerto see worker status, enable/disable workers, and adjust load‑factor values. \n - Configure timeouts, retries, and
maxattemptsin theProxyPassline to control how Apache handles unresponsive backends. \n - Check access logs on each backend; with
byrequestsyou should see roughly equal request counts over a short interval if the workers are healthy and the traffic is uniform. \n
Failure Modes
\n- \n
- Backend unresponsiveness: after the configured number of retries Apache returns HTTP 502 (Bad Gateway) to the client. \n
- Worker drain: if a worker is manually set to “drain” via the balancer‑manager, Apache stops sending new requests to it; existing connections finish, and clients may see 503 (Service Unavailable) if all workers are drained. \n
- Mis‑balanced load: using
byrequestswith highly variable request sizes can cause uneven resource utilization; considerlbmethod=bytrafficorlbmethod=bybusynessfor heterogeneous workloads. \n
When the Design Would Change
\nYou would revisit this minimal design if any of the following apply:
\n- \n
- Sticky sessions are required (e.g., for stateful applications). Add
stickysessionparameters and possiblyProxySet stickysession=JSESSIONID. \n - TLS offload is moved to a dedicated device (hardware load balancer or separate TLS termination proxy). In that case Apache would listen on plain HTTP only, and the front‑end trust boundary shifts. \n
- You need more sophisticated health checks (e.g., HTTP‑based checks with specific response codes). Replace simple TCP connectivity with
ProxyPassretryandtimeouttuned to your application, or use an external health‑check agent. \n - The traffic pattern demands a different load‑balancing algorithm (consistent hashing, least‑time, etc.). Swap the
lbmethodmodule and adjust theProxySetline accordingly. \n
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.