Configuring Apache HTTP Server as a Reverse Proxy and Load Balancer

The following procedure outlines the deployment of an Apache HTTP Server instance configured as a reverse proxy and load balancer for multiple backend application servers. The architecture utilizes a front-end proxy layer distributing traffic across two back-end web nodes.

Environment Preparation and Back-End Node Configuration

Initialize two Linux instances (designated as app-node-01 and app-node-02) running CentOS 7. Both will serve as destination web servers listening on TCP port 8080. Disable network packet filtering and security modules, then apply hostnames and package repositories.

systemctl stop firewalld && systemctl disable firewalld
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
yum install -y epel-release
yum install -y gcc gcc-c++ make tree lrzsz glibc
tyum install -y httpd

Modify the default listening directive to avoid conflicts with system services.

sed -i 's|^Listen 80$|Listen 8080|' /etc/httpd/conf/httpd.conf
systemctl restart httpd
ss -tlnp | grep :8080

Assign distinct response payloads to identify routing destinations.

echo "Response from app-node-01:8080" > /var/www/html/index.html
# Repeat on app-node-02 with an appropriate identifier
curl http://<backend-ip-1>:8080
curl http://<backend-ip-2>:8080

Apache Compilation and Installation

The proxy server requires building Apache from source to ensure flexibility with module selection. Prerequisite development libraries include APR, PCRE, and OpenSSL.

yum install -y apr-devel apr-util-devel pcre-devel openssl-devel
cd /opt/src
wget https://archive.apache.org/dist/httpd/httpd-2.4.58.tar.gz
tar xzf httpd-2.4.58.tar.gz
cd httpd-2.4.58
./configure --prefix=/usr/local/apache-lb \
            --enable-so \
            --enable-modules=most \
            --enable-proxy \
            --enable-proxy-http \
            --enable-proxy-balancer
make -j$(nproc) && make install
ln -sf /usr/local/apache-lb /usr/local/apache
echo $?

APR abstracts OS-specific calls, enabling portable execution. PCRE handles regular expressions, while OpenSSL secures transport layers. Validate the binary configuration before launching.

/usr/local/apache/bin/apachectl configtest
/usr/local/apache/bin/apachectl start

Reverse Proxy and Load Balancer Definition

Extract template directives from the primary configuration directory and isolate proxy settings into a dedicated snippet. This minimizes configuration coupling.

Set the server identifier in conf/httpd.conf:

ServerName proxy-host.local:80
Include conf/extra/*.conf

Create conf/extra/lb-config.conf to declare upstream targets and enable request distribution.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

ProxyRequests Off

<Proxy balancer://web-farm>
    BalancerMember http://<backend-ip-1>:8080
    BalancerMember http://<backend-ip-2>:8080
</Proxy>

ProxyPass /api balancer://web-farm
ProxyPassReverse /api balancer://web-farm

The slotmem_shm module is mandatory for shared memory tracking in newer Apache versions. Omitting it triggers startup failures related to provider lookup. Append the module directive to the isolation file or the global configuration before reloading.

Verify syntax and apply the changes:

/usr/local/apache/bin/apachectl -t
/usr/local/apache/bin/apachectl restart
netstat -tlnp | grep :80

Traffic Distribution Verification

Sequential requests hitting the proxy endpoint demonstrate round-robin distribution. Activate the administrative monitoring interface to inspect node states dynamically.

<Location /lb-admin>
    SetHandler balancer-manager
    Require ip 127.0.0.1 ::1 192.168.50.0/24
</Location>

Apply the adjustment without interrupting active connections:

/usr/local/apache/bin/apachectl graceful

Access the dashboard via http://<proxy-ip>/lb-admin to visualize weight allocations and member health. Network restrictions should be enforced in production environments to prevent unauthorized exposure.

Virtual Host Integration

Replace direct IP access with DNS-based routing to simulate real-world client behavior. Isolate the proxy rules within a VirtualHost block.

<VirtualHost *:80>
    ServerAdmin admin@lab.local
    DocumentRoot "/var/www/html/proxy-root"
    ServerName portal.internal.local
    ErrorLog logs/internal-error.log
    CustomLog logs/internal-access.log combined
    ProxyPreserveHost On
    ProxyPass / balancer://web-farm
    ProxyPassReverse / balancer://web-farm
</VirtualHost>

Refresh the configurasion:

/usr/local/apache/bin/apachectl configtest && /usr/local/apache/bin/apachectl graceful

Map the target domain locally:

<proxy-ip>  portal.internal.local  internal.local

Resolve DNS resolution gaps and validate end-to-end routing through browser requests to http://portal.internal.local. Fine-tune load balancing weights and timeout parameters directly within the <Proxy> definition if asymmetrical workloads are anticipated.

Production deployments often favor specialized proxies over Apache for high-concurrency scanarios. Apache relies on the select/poll connection handling model, whereas alternatives leverage epoll or asynchronous I/O architectures. Consequently, tools built specifically for edge traffic management typically deliver superior throughput and lower latency under heavy loads. Apache remains viable for standardized routing requirements where native Apache features or legacy compatibility dictate the infrastructure stack.

Tags: Apache HTTP Server reverse proxy Load Balancing Linux Administration Source Compilation

Posted on Mon, 07 Sep 2026 16:18:59 +0000 by ojeffery