mod_proxy_balancer requires the service of mod_proxy, and it provides load balancing for all the supported protocols.
mod_proxy_balancer has following scheduling algorithm
- mod_lbmethod_byrequests
- mod_lbmethod_bytraffic
- mod_lbmethod_bybusyness
- mod_lbmethod_heartbeat
Followings are the example of a balancer configuration:
<Proxy "balancer://mycluster"> BalancerMember "http://192.168.1.50:80" BalancerMember "http://192.168.1.51:80" </Proxy> ProxyPass "/test" "balancer://mycluster" ProxyPassReverse "/test" "balancer://mycluster"
Followings are another example of balancer configuration:
<VirtualHost *:80> ServerName cdn.foo.net ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Require all granted </Proxy> <Proxy balancer://mycluster> BalancerMember http://192.168.10.7:80 route=1 connectiontimeout=1 BalancerMember http://192.168.10.8:80 route=2 connectiontimeout=1 ProxySet lbmethod=byrequests ProxySet stickysession=ROUTEID </Proxy> ProxyPass "/" "balancer://mycluster" ProxyPassReverse "/" "balancer://mycluster" DocumentRoot "/pub/cdn.qsok.com/" CustomLog /var/log/httpd/cdn.its-newid.net-access.log combined ErrorLog /var/log/httpd/cdn.its-newid.net-error.log </VirtualHost>
If you encounter errors like below in case that you use PHP combined with Apache, you will need to use other configuration. Probably you may not able to get any session data from your client.
Below configuration will enable you to use your PHP codes as designed.
<VirtualHost *:80> ServerName cdn.foo.net ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Require all granted </Proxy> ProxyPass /balancer-manager ! ProxyPass / balancer://mycluster/ stickysession=BALANCEID nofailover=On ProxyPassReverse / http://192.168.10.7:80 ProxyPassReverse / http://192.168.10.8:80 <Proxy balancer://mycluster> BalancerMember http://192.168.10.7:80 route=1 connectiontimeout=1 BalancerMember http://192.168.10.8:80 route=2 connectiontimeout=1 ProxySet lbmethod=byrequests </Proxy> <Location /balancer-manager> SetHandler balancer-manager Order deny,allow Allow from all </Location> DocumentRoot "/pub/cdn.qsok.com/" CustomLog /var/log/httpd/cdn.its-newid.net-access.log combined ErrorLog /var/log/httpd/cdn.its-newid.net-error.log </VirtualHost>