i needed to set up apache2 as a reverse proxy that will forward requests to few backends. yes – i know that there are better tools to do it – like haproxy or nginx – but in this case apache2 was preferred for the simplicity of the setup. requirements:
- sticky sessions – in normal conditions all subsequent requests from a visitor should be handled by the same backend node
- failover – once server is marked as down it should not get more requests forwarded to it, even if that means that user will be handled by a new backend in the middle of their session
- filover not just on timeouts but also on specific backend responses like 503s
working config:
<VirtualHost ...>
...
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://backends>
BalancerMember http://backend0.some.domain:80 retry=60s timeout=10s route=1
BalancerMember http://backend0.some.domain:80 retry=60s timeout=10s route=2
ProxySet stickysession=ROUTEID
ProxySet failonstatus=500,503
</Proxy>
ProxyPass / balancer://backends/
ProxyPassReverse / balancer://backends/
...
</VirtualHost>