Enable mod_proxy module to configure reverse proxy settings in Apache httpd. This example demonstrates setting up a reverse proxy and load balancing.
mod_proxy is included in the httpd package and is enabled by default.
mod_proxy Modules# Verify mod_proxy modules are enabled
[root@www ~]# grep "mod_proxy" /etc/httpd/conf.modules.d/00-proxy.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
...
# Create and edit the reverse proxy configuration
[root@www ~]# vi /etc/httpd/conf.d/reverse_proxy.conf
# Add the following configuration
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://node01.emc.world/
ProxyPassReverse / http://node01.emc.world/
</IfModule>
# Reload httpd to apply changes
[root@www ~]# systemctl reload httpd
If SELinux is enabled, modify the policy to allow network connections.
# Set SELinux boolean for httpd network connectivity
[root@www ~]# setsebool -P httpd_can_network_connect on
Access the front-end server (www.emc.world) to verify that responses are correctly proxied from the back-end server (node01.emc.world).
Set up load balancing between multiple backend servers.
# Edit the reverse proxy configuration for load balancing
[root@www ~]# vi /etc/httpd/conf.d/reverse_proxy.conf
# Add or update the following configuration
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://cluster lbmethod=byrequests
<Proxy balancer://cluster>
BalancerMember http://node01.emc.world/ loadfactor=1
BalancerMember http://node02.emc.world/ loadfactor=1
</Proxy>
</IfModule>
# Reload httpd to apply changes
[root@www ~]# systemctl reload httpd
Access the front-end server (www.emc.world) to verify that responses are correctly balanced and proxied from the back-end servers (node01.emc.world and node02.emc.world).
This setup allows Apache httpd to act as a reverse proxy and load balancer, distributing requests across multiple backend servers for improved performance and reliability.