Tuesday, July 14, 2020

How to use Apache reverse proxy as A Load Balancer

Description: Here I have explained how to use Apache Reverse Proxy as Load Balancer. In this link I have explained, how to configure reverse proxy to hide Backend application and port number. I have covered redirection part, In this tutorial I will explained how can we use reverse proxy as Loadbalancer.

Procedure: 
  • As a Pre requisite we need to install Apache server with Apache Proxy Modules like mod_proxy, mod_proxy_http, mod_proxy_balancer and mod_lbmethod_byrequests
  • You can verify by using httpd -M command
  • You can also find modules in apache configuration file
# vi /etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_h
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
  • Restart apache server to after enable it. 
Configuring Backend Server: I have created 3 application server with same App directory as follow.
http://10.0.0.1:5000/App
http://10.0.0.2:5000/App
http://10.0.0.3:5000/App

Configuring the Reverse Proxy: To configure apache reverse proxy load balancer we need to add some configuration in apache configuration file.


# vi /etc/httpd/conf/httpd.conf
<VirtualHost *:80>

<Proxy balancer://cluster>

BalancerMember http://10.0.0.1:5000/App
BalancerMember http://10.0.0.2:5000/App
BalancerMember http://10.0.0.3:5000/App


ProxyPreserveHost On
ProxyPass / balancer://cluster/
ProxyPassReverse / balancer://cluster/

</VirtualHost>

Here ‘<Proxy balancer://cluster>’ is part where we mention the all the instances and 'ProxyPass' is handle all redirection. After making changes restart apache service.

# systemctl restart httpd

No comments:

Post a Comment