Configuration file at /etc/haproxy/haproxy.cfg:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
errorfile 503 /usr/share/haproxy/503.http
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend nonsecure_entry *:80
redirect scheme https
frontend secure_entry *:443
default_backend myapp
backend myapp
errorfile 503 /usr/share/haproxy/503.http
balance roundrobin
server myapp1 127.0.0.1:8080 check
The configuration file is pretty much left to default, as you can see. The
important lines are the ones defining the errorfile 503.
I have edited the /usr/share/haproxy/503.http to a custom HTML page:
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html
<!DOCTYPE html>
<html>
<head><title>503 Error</title></head>
<body>This custom error-page is not displayed :(</body>
</html>
Please note that I did use CRLF instead of just LF to comply with the HTTP
protocol.
However, the result is that this custom 503 errorfile is never used by HAProxy.
Neither is there an error displayed that something went wrong.
I know it is not an issue in my setup, because I disabled the HAProxy service,
and then there was no error-page at all (browser timeout).
And I also verified that the given configuration file was actually used.
I also made sure that the 503.http is readable and owned by haproxy:haproxy
(verified with su haproxy -s /bin/bash followed by cat
/usr/share/haproxy/503.http which displayed the file).
The version I am using:
haproxy -v
HA-Proxy version 1.5.18 2016/05/10
Copyright 2000-2016 Willy Tarreau <[email protected]>
What is very peculiar, is that there is no warning/error message in the server
output. As you can see, I just restarted it again, and everything seems normal:
haproxy.service - HAProxy Load Balancer
Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled; vendor
preset: disabled)
Active: active (running) since Sun 2018-08-19 18:32:00 CEST; 2s ago
Main PID: 7136 (haproxy-systemd)
CGroup: /system.slice/haproxy.service
7136 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg
-p /run/haproxy.pid
7137 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p
/run/haproxy.pid -Ds
7138 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p
/run/haproxy.pid -Ds
Aug 19 18:32:00 MASKED systemd[1]: Started HAProxy Load Balancer.
Aug 19 18:32:00 MASKED systemd[1]: Starting HAProxy Load Balancer...
Aug 19 18:32:00 MASKED haproxy-systemd-wrapper[7136]: haproxy-systemd-wrapper:
executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
I've looked into the source code on your github page, and I see that the 503 I
am getting is precisely the output from the source code in proto_http.c, which
is:
[HTTP_ERR_503] =
"HTTP/1.0 503 Service Unavailable\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html><body><h1>503 Service Unavailable</h1>\nNo server is available to handle
this request.\n</body></html>\n",
Additionally I verified that there was no caching going on, this was an actual
response from haproxy. Therefore, the resulting observation is that haxproxy is
effectively ignoring the errorfile definition in the configuration file -
without warning or error.
Best regards, Yeti;