I'm using 503 HTTP Status and a coming soon page for maintenance mode.
Is there any way to get HAproxy serving server-side generated 503 page instead of the default blank/unavailable page?
I'm using Openshift + HAproxy + Cloudflare + PHP.
Thanks in advance.
Haproxy config (some comments removed):
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
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
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:5000
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check
Best Answer
This isn't the actual question you should be asking. HAProxy always uses the server's response. The error file is only used for errors generated internally by HAProxy.
If you check your web server logs, you'll find that these specific requests are not actually being sent to the web server.
This is happening because HAProxy thinks your server is down... because it's getting 503 from the server in response to the health check.
If the server were returning 502 or 400 or any error code on the health checks, you'd still receive the 503 from HAProxg because the server is, officially, down.
You have apparently redacted the line
option httpchk
from the configuration you posted, but it has to be there, or HAProxy would only do a layer 4 check, and this wouldn't be happening.The simplest solution is to remove that line from the backend or default config.