Category Archives: haproxy

Serve error code via Haproxy.

Quest: Serve error code via Haproxy. For testing reasons etc.

1) Creaate a backend:
backend error
mode http
log global
option httplog
errorfile 500 /etc/haproxy/errorpages/503.http
errorfile 502 /etc/haproxy/errorpages/503.http
errorfile 503 /etc/haproxy/errorpages/503.http
errorfile 504 /etc/haproxy/errorpages/503.http

2) Create the errorpage:

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

<title>Title of your site</title>
<body style=”font-family:Arial,Helvetica,sans-serif;”>




3) Add the use backend
use_backend error if { hdr(Host) -i }

4) What’s worth considering is adding the “testing” mode for some IP’s. Add a new acl:
acl office_ips src

5) Change the use_backend to

use_backend error if { hdr(Host) -i } office_ips

^THIS will redirect every request coming from or, that comes from the IPs declared in office_ips to the backend “error” and show an error

Mind the gap! (haproxy)

Haproxy is an awesome software. If you’re not sure if your config is correct you can check it by:
haproxy -c -f /path/to/your/config.conf

-c is for check
-f is for file


The check won’t notice if spaces are in the wrong place. So…

hdr(Host) and hdr (Host) are both correct for Haproxy check config. But it won’t work (well it didin’t work for me). hdr(Host) is correct (no space between hdr and (Host)).