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 webmaster@example.com
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>