1

My use case is as follows: In the config I have one frontend that listens on HTTPS and serves to a backend The backend has one or more servers. When all of the backend servers are down, I want to serve a sorry page, hosted in another place to give some info of the outage.

My first attempt was to put the sorry server in the same backend as the regular servers, but with a check backup option. This failed since the host header for the health checks cannot be different per server.

I assume that I need to add a separate backend section for the sorry server, so that I can configure the correct health checks and all, but how do I configure the frontend to switch over to the sorry backend if the regular backend is down?

HA-Proxy version 1.9.16-1ppa1~bionic

Johnathan
  • 111
  • 2
  • One way is to change the 503 error page to redirect to the sorry page. But then the URL would change and a refresh would not bring the user back to the original service once restored – Johnathan Dec 22 '20 at 12:35
  • It sounds like you want a custom 503. Try this: https://serverfault.com/questions/249109/how-can-i-use-a-custom-503-error-document-when-haproxy-sends-a-503-http-code – tater Dec 22 '20 at 12:47
  • No as per my above comment that did not really produced the desired solution : ) I want the main URL to be unchanged so that when a user refreshes the page after the regular backend is up again, they will get to the service once again – Johnathan Dec 22 '20 at 12:50
  • A custom 503 should not do a redirect. – tater Dec 22 '20 at 12:53
  • Ah you mean take the web code from the external server and put it as the 503 page on HAproxy. That is not possible in my case unfortuately. – Johnathan Dec 22 '20 at 15:01
  • Your first attempt seems like the right one but why do you need the host headers to be different per server? If you can get the servers to all respond with the same host header the `check backup` solution should work. Alternatively, you can do something with `errorfile` like this: https://serverfault.com/questions/249109/how-can-i-use-a-custom-503-error-document-when-haproxy-sends-a-503-http-code – Ladadadada Dec 22 '20 at 16:19
  • From your front end, you should be able to check the count of active servers in a given backend, and then make a backend selection based on that. – GregL Dec 23 '20 at 01:39
  • the external sorry page server is hosted externally at a web hotell and need the correct host header unfortuately. How do I check the active servers in any given backend? : P – Johnathan Dec 23 '20 at 22:18

1 Answers1

0

You can use nbsrv
https://cbonte.github.io/haproxy-dconv/2.2/configuration.html#7.3.1-nbsrv

It can be used this way:

frontend https
    bind (...)
    acl backend_up_foo nbsrv(foo) -m int gt 0
    use_backend foo if backend_up_foo
    default_backend sorry

backend foo
    (...)

backend sorry
    http-request set-header Host sorry.example.org
    (...)

To display sorry page without redirecting users i also use rewrites in Apache, which serves the "sorry page":

<Directory "/path/to/sorry/page">
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*) index.html
(...)
</Directory>

If the "sorry page" has images or other files they can be put in that directory and RewriteCond will cause Apache to serve them properly. All other URLs are redirected internally in Apache to the actual "sorry page".

tbielaszewski
  • 411
  • 2
  • 5