Skip to content

Instantly share code, notes, and snippets.

@sts
Last active January 11, 2023 11:12
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save sts/62d8dd59221ab68661aa to your computer and use it in GitHub Desktop.
Save sts/62d8dd59221ab68661aa to your computer and use it in GitHub Desktop.
HAProxy Maintenance Page
#
# Proof of concept for a HAProxy maintenance mode
#
#
# Control the maintenance page during runtime using the stats socket:
#
# To put the whole site in maintenance mode (for all IPs):
# > add acl #0 0.0.0.0/0
#
# To exclude your own ip, so you are able to test things out:
# > add acl #1 8.8.8.8
#
# To exit maintenance mode again simply remove the mask from #0 again:
# > del acl #0 0.0.0.0/0
#
frontend web
bind 0.0.0.0:80
mode http
default_backend web_backend
# use this in case of real errors
errorfile 503 /etc/haproxy/errors/maintenance.http
# maintenance mode - disabled by default
acl web_maintenance src --
acl web_maintenence_ex src --
use_backend web_maintenance if web_maintenance !web_maintenence_ex
backend web
mode http
balance roundrobin
server web01 127.0.0.1:8080 inter 500 rise 3 fall 1 weight 100 slowstart 30s
backend web_maintenence
mode http
errorfile 503 /etc/haproxy/errors/maintenance.http
@cmeury
Copy link

cmeury commented Dec 8, 2014

Just saying, there is a typo here, the backend is called "web_maintenEnce", but the use_backend directive references "web_maintenAnce".

@robert1112
Copy link

robert1112 commented May 16, 2018

Hi How should I use this?

@magec
Copy link

magec commented May 10, 2022

The idea behind is completing the acl in runtime, so web_maintenance is mapped to ACL #0 and web_maintenence_ex to #1. Given so, once running, by executing the lines shown, you can control the behavior of the acl, thus changing the way haproxy process requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment