HAProxy - putting up a maintenance page

Is there an easy way to dissable All backends in haproxy, and instead serve an appropriate maintenance page (for http requests)?

I've read a little about the dissabled option, which I understand is per-server, but am wondering if there is a way to simply stop traffic to all backends?


The backup keyword is what we use for this. See this example:

listen example_com 0.0.0.0:8001
...
option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www.example.com\r\nUser-Agent:\ HAProxy
server  web01 10.1.31.21:80 cookie cookie_web01 check inter 5000 rise 2 fall 5 disabled
server  web02 10.1.31.22:80 cookie cookie_web02 check inter 5000 rise 2 fall 5 disabled
server  prx   10.1.31.10:9000  backup

Here both servers web01 and web02 are set to disabled, in which case the backup server prx on 10.1.31.10:9000 will be used, which serves a maintenance page. The prx server in our case is the HAProxy server itself and on port 9000 runs an Apache HTTPD, serving the maintenance content:

<VirtualHost *:9000>
    ServerName  example.com
    ServerAdmin [email protected]

    DocumentRoot /var/www/example.com/errors/
    <Directory /var/www/example.com/errors/>
        Options -Indexes
    </Directory>

    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}/systemDown.html -f
    RewriteCond %{SCRIPT_FILENAME} !systemDown.html
    RewriteRule ^.*$ /systemDown.html [R=503,L]
    ErrorDocument 503 /systemDown.html

</VirtualHost>

This blog post helped me: https://rimuhosting.com/knowledgebase/creating-a-maintenance-page-for-your-site

It suggests setting/customizing the 503 error handler:

errorfile 503 /var/www/503maintance.html

Note: you need to include the http headers in the error handler file:

HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html

What about redirect or redir

A simple redir example

server srv1 10.0.0.10:80 redir http://maintenance.domain.com check

redirect can be set in all by defaults option.