2

I am trying to configure load balancing in apache httpd.

I have 2 nodes that are both active. But I want traffic to only go to a node which responds positively to a GET at a particular path.

The same is possible in ngnix and haproxy but I am unable to use those at my current project.

user5637515
  • 21
  • 1
  • 2

1 Answers1

3

You can use the mod_proxy_hcheck module:

https://httpd.apache.org/docs/trunk/mod/mod_proxy_hcheck.html

Relevant Snippet

ProxyHCExpr ok234 {%{REQUEST_STATUS} =~ /^[234]/}
ProxyHCExpr gdown {%{REQUEST_STATUS} =~ /^[5]/}
ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/}

<Proxy balancer://foo>
  BalancerMember http://www.example.com/  hcmethod=GET hcexpr=in_maint hcuri=/status.php
  BalancerMember http://www2.example.com/  hcmethod=HEAD hcexpr=ok234 hcinterval=10
  BalancerMember http://www3.example.com/ hcmethod=TCP hcinterval=5 hcpasses=2 hcfails=3
  BalancerMember http://www4.example.com/
</Proxy>

ProxyPass "/" "balancer://foo"
ProxyPassReverse "/" "balancer://foo"
Sohel Katchi
  • 191
  • 11