0
votes

I can't clearly understand how Haproxy performs health checks in http mode.

I need to resend http request to another server (next in list of backend servers), if first one returned some error status code (for example, 503). I need following behaviour of Haproxy: 1) I receive some HTTP request 2) I send it to the first server 3) If I get 503 (or some other error code), this HTTP request must be send to the next server 4) If It returns 200 code, next http requests of this tcp session goes to first server

I know it's easy to implement in nginx (using proxy_next_upstream, I suppose). But I need to use Haproxy, because software I need to connect works on the layer 4 and I can't change it, so it need to keep groups of http messages in the same tcp session. I can keep them in the same session in haproxy, but not in nginx.

I know about httpchk and observe, but they are not what I need. First one allows me to send some http request, not http request I received (I need to analyse http traffic to decide what http status I will answer). Second marks my servers as dead and doesn't send messages to it anymore, but I need this messages to by analysed. I really need behaviour like nginx, but with ability to have http messages in the tcp sessions. Probably there is some nice way to implement it with ACL?

Could anyone please give me a detailed explanation how haproxy handles load balancing in http mode or offer some solution to my problem?

UPDATE: For example, when I tried to do it with observe, I used configuration:

global
log 127.0.0.1   local0
maxconn 10000
user haproxy
group haproxy
daemon

defaults
log global
option  dontlognull
retries 3
maxconn 10000
contimeout  10000
clitimeout  50000
srvtimeout  50000

listen zti 127.0.0.1:1111
mode http
balance roundrobin
server zti_1 127.0.0.1:4444 check observe layer7 error-limit 1 on-error mark-down
server zti_2 127.0.0.1:5555 check observe layer7 error-limit 1 on-error mark-down

Thanks, Dmitry

1
Please post your configuration, - Tan Hong Tat
@Tan Hong Tat actually, I still didn't write the nice config, because I don't know how to implement it. But, I appended my post with configuration I have used when tried to do what I want with "observe" - RedRus

1 Answers

0
votes

You can use the option httpchk.

When "option httpchk" is specified, a complete HTTP request is sent once the TCP connection is established, and responses 2xx and 3xx are considered valid, while all other ones indicate a server failure, including the lack of any response.

listen zti 127.0.0.1:1111
mode        http
balance     roundrobin
option      httpchk HEAD / HTTP/1.0
server      zti_1 127.0.0.1:4444 check inter 5s rise 1 fall 2
server      zti_2 127.0.0.1:5555 check inter 5s rise 1 fall 2

Source: https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#option%20httpchk