{"id":3048,"date":"2020-02-09T20:31:33","date_gmt":"2020-02-09T19:31:33","guid":{"rendered":"https:\/\/kudzia.eu\/b\/?p=3048"},"modified":"2020-02-09T20:31:51","modified_gmt":"2020-02-09T19:31:51","slug":"apache2-as-a-reverse-proxy-with-sticky-sessions-and-backend-failover","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2020\/02\/apache2-as-a-reverse-proxy-with-sticky-sessions-and-backend-failover\/","title":{"rendered":"apache2 &#8211; reverse proxy with sticky sessions and fail-over"},"content":{"rendered":"<p>i needed to set up apache2 as a reverse proxy that will forward requests to few backends. yes &#8211; i know that there are better tools to do it &#8211; like haproxy or nginx &#8211; but in this case apache2 was preferred for the simplicity of the setup. requirements:<\/p>\n<ul>\n<li>sticky sessions &#8211; in normal conditions all subsequent requests from a visitor should be handled by the same backend node<\/li>\n<li>failover &#8211; 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<\/li>\n<li>filover not just on timeouts but also on specific backend responses like 503s<\/li>\n<\/ul>\n<p>working config:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;VirtualHost ...&gt;\r\n...\r\nHeader add Set-Cookie &quot;ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=\/&quot; env=BALANCER_ROUTE_CHANGED\r\n&lt;Proxy balancer:\/\/backends&gt;\r\n BalancerMember http:\/\/backend0.some.domain:80 retry=60s  timeout=10s route=1\r\n BalancerMember http:\/\/backend0.some.domain:80 retry=60s  timeout=10s route=2\r\n ProxySet stickysession=ROUTEID\r\n ProxySet failonstatus=500,503\r\n&lt;\/Proxy&gt;\r\n\r\nProxyPass \/ balancer:\/\/backends\/\r\nProxyPassReverse \/ balancer:\/\/backends\/\r\n...\r\n&lt;\/VirtualHost&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>i needed to set up apache2 as a reverse proxy that will forward requests to few backends. yes &#8211; i know that there are better tools to do it &#8211; like haproxy or nginx &#8211; but in this case apache2 was preferred for the simplicity of the setup. requirements: sticky sessions &#8211; in normal conditions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[106],"class_list":["post-3048","post","type-post","status-publish","format-standard","hentry","category-unimportant","tag-apache2"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=3048"}],"version-history":[{"count":3,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3048\/revisions"}],"predecessor-version":[{"id":3051,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/3048\/revisions\/3051"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=3048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=3048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=3048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}