When a user accesses the backend with an assigned cookie, we want to display a 503 error instead of failing over if the corresponding backend server is down.
Currently, we retrieve the cookie and apply filtering using an ACL. However, in the HAProxy logs, we see:
Thank you for your response.
Could you tell me if there are any other settings that might override haproxy.cfg?
I have specified no option redispatch in both the defaults and backend sections.
However, redispatch is still occurring…
Below is my backend configuration.
There are some extra settings, but since redispatch is not being disabled, I tried handling it with an ACL, but it does not work as expected.
backend servers1
balance leastconn #option redispatch 0
no option redispatch
option httpchk
option prefer-last-server
mode http
http-check disable-on-404
option http-server-close
http-check send meth GET uri / ver HTTP/1.1 hdr Host xxxxxx.net
http-check expect status 200
http-request set-header X-Forwarded-For %[src]
http-request set-header X-Forwarded-By %[hostname]
cookie SERVERID insert indirect nocache
stick-table type ip size 1m expire 30m peers haproxy-peers-backend
"# stick on src
stick on req.cook(SERVERID)
acl has_cookie req.cook(SERVERID) -m found
acl cookie_apache01 req.cook(SERVERID) -m str “SERVERID=aaaaa”
acl cookie_apache02 req.cook(SERVERID) -m str “SERVERID=bbbbb”
acl apache01_down srv_is_up(apache01) eq 0
acl apache02_down srv_is_up(apache02) eq 0
http-request set-log-level info if cookie_apache01
http-request set-log-level info if cookie_apache02
http-request set-log-level alert if apache01_down
http-request set-log-level alert if apache02_down
http-request deny if cookie_apache01 apache01_down
http-request deny if cookie_apache02 apache02_down
force-persist if cookie_apache01
force-persist if cookie_apache02
use-server apache01 if cookie_apache01
use-server apache02 if cookie_apache02
default-server maxconn 5000 on-marked-down shutdown-sessions
server apache01 192.168.0.2:80 cookie aaaaa check inter 2000 fall 3 rise 2 maxconn 5000
server apache02 192.168.0.3:80 cookie bbbbb check inter 2000 fall 3 rise 2 maxconn 5000
frontend https_front
bind *:443 ssl crt /etc/haproxy/certs/haproxy.pem
mode http
option httplog clf
default_backend servers1
capture request header Cookie len 128
capture request header User-Agent len 64
acl domain1 req_ssl_sni -i xxxxx.net
’ # acl domain2 req_ssl_sni -i yyyyyy.net
use_backend servers1 if domain1
’ # use_backend servers2 if domain2
stick-table type ip size 20k expire 10s store http_req_rate(10s) peers haproxy-peers-f
http-request track-sc0 src
acl exceeds_rate_limit sc_http_req_rate(0) gt 20
http-request set-log-level alert if exceeds_rate_limit
http-request deny if exceeds_rate_limit
capture request header Cookie len 128
capture request header Host len 64
capture request header User-Agent len 128
frontend http_front
bind *:80
mode http
stick-table type ip size 1m expire 10s store http_req_rate(10s)
acl exceeds_rate_limit sc_http_req_rate(0) gt 20
http-request set-log-level alert if exceeds_rate_limit
http-request deny if exceeds_rate_limit
redirect scheme https if !{ ssl_fc }
backend servers1
balance leastconn #option redispatch 0
no option redispatch
option httpchk
option prefer-last-server
mode http
http-check disable-on-404
option http-server-close
http-check send meth GET uri / ver HTTP/1.1 hdr Host xxxxxx.net
http-check expect status 200
http-request set-header X-Forwarded-For %[src]
http-request set-header X-Forwarded-By %[hostname]
cookie SERVERID insert indirect nocache
stick-table type ip size 1m expire 30m peers haproxy-peers-backend
'# stick on src
stick on req.cook(SERVERID)
acl has_cookie req.cook(SERVERID) -m found
acl cookie_apache01 req.cook(SERVERID) -m str “SERVERID=aaaaa”
acl cookie_apache02 req.cook(SERVERID) -m str “SERVERID=bbbbb”
acl apache01_down srv_is_up(apache01) eq 0
acl apache02_down srv_is_up(apache02) eq 0
http-request set-log-level info if cookie_apache01
http-request set-log-level info if cookie_apache02
http-request set-log-level alert if apache01_down
http-request set-log-level alert if apache02_down
http-request deny if cookie_apache01 apache01_down
http-request deny if cookie_apache02 apache02_down
force-persist if cookie_apache01
force-persist if cookie_apache02
use-server apache01 if cookie_apache01
use-server apache02 if cookie_apache02
default-server maxconn 5000 on-marked-down shutdown-sessions
server apache01 192.168.0.2:80 cookie aaaaa check inter 2000 fall 3 rise 2 maxconn 5000
server apache02 192.168.0.3:80 cookie bbbbb check inter 2000 fall 3 rise 2 maxconn 5000
</pre>
I had added extra configurations as a result of various adjustments.
I have now made the cfg very simple.
However, even with this, failover still occurs…
global
log 127.0.0.1 local0 debug
log stdout format raw local0 debug
maxconn 20480
daemon
nbthread 4
master-worker
stats socket /var/run/haproxy.sock mode 660 level admin