Help me to configurations backend with proxy server

Hello !
I used haproxy version 1.8.8
I have backend is multi-servers, but some server use proxy server. It use only one public IP to the internet but mapping by domain (same virtual-host). All backend servers is same all mandates, functions …

I have diagram:

Clients --> Haproxy-Server ---> Server 1 ( have IP: xxx.yyy.zzz.kkk  domain: testhaproxy1.com )
                           ---> Server 2 ( have IP: aaa.bbb.ccc.ddd  domain: testhaproxy2.com )
                           ---> Server 3 ( have IP: aaa.bbb.ccc.ddd  domain: testhaproxy3.com - same IP with server 2 )
                           ---> Server 4 ( have IP: aaa.bbb.ccc.ddd  domain: testhaproxy4.com- same IP with server 2 )

My current haproxy.cfg

frontend http-in
        bind *:80
        mode http 
	use_backend bke_servers

backend bke_servers
	balance roundrobin
	option forwardfor
	option external-check
	external-check path "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
	external-check command "/var/lib/haproxy/loadbalancer"
	default-server inter 15s downinter 5s fall 3 rise 2
	#http-send-name-header Host
	server server1 testhaproxy1.com:80 check weight 20
	server server2 testhaproxy2.com:80 check weight 20
	server server3 testhaproxy3.com:80 check weight 30
	server server4 testhaproxy4.com:80 check weight 30

Proplem:
1/ When I use check health by httpchk GET - server 2,3,4, the haproxy check always send request to their IP. So, it failed. I need write the shell script to check by external-check ( if server name is server1 --> send request check to testhaproxy1.com --> if ok exit 1 else exit -1).
2/ When I tried send request to proxy server - I got failed results, it return code status 502 Bad Gateway. And I tried to check root problem is haproxy always send request to IP - not to domain of each servers.

I tried to use http-request set-header Host - but it only used for only one server. I don’t know:
How to I can set Host same: http-request set-header Host testhaproxy1.com if { server_name server1 }
Or How to: I can configuration haproxy send request exactly to domain - not to IP ?

That doesn’t make sense.

You are load-balancing via round-robin between those 4 servers, they are supposed to serve the same domains, so why don’t you send the same health-check domain to all of them.

Check the docs to know howto send specific host headers in health checks:

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

Haproxy won’t change the host header. If it was wrong or non-existent in the request, it will be wrong on the backend also.

Hi lukastribus
Maybe, you do not understand exactly my case. Other, I have not only 4 servers backend - it is many servers (more than 10 servers, and have some servers have same public internet IP ) and server run HAProxy is Independent server. Please read again my problem.
I will detail more: when I used httpchk-check

backend bke_allservers
        balance roundrobin
        option forwardfor
        option httpchk HEAD /api/v1/rest/serverstatus
        http-check expect status 200
	default-server inter 10s fall 3 rise 2
        server server1 testhaproxy1.com:80 check
        server server2 testhaproxy2.com:80 check
        server server3 testhaproxy3.com:80 check
.....
        server serverN testhaproxyn.com:80 check

As you know, when you used VPS on one main physical server ( physical server public only one IP to the internet) each VPS will distinguished through domain mapping. (example: testhaproxy2.com mapping with VPS2, testhaproxy3.com mapping with VPS3 ). So, all domains mapped on this physical server will used only one public IP. Wen you use command ping to them - it only return one IP. Example public IP is: 123.12.123.123, on this case when you run command:
curl -s -k http://testhaproxy1.com/api/v1/rest/serverstatus ==> the result will return ok and head status is 200
But:
curl -s -k http://123.12.123.123/api/v1/rest/serverstatus ==> the result will return Bad Gateway and head status is 404

So, I got problem - HAProxy always send request check for IP of each domain - not send to domain.

And same with case health-check when I send request to HAProxy-server - it will call backend but sent this request to IP of each server. Detail: I see on HAProxy log - it print server [06/Aug/2019:03:37:17.175] http-in~ bke_allservers/server3 - and return status 404 - Not Found. And I get apache access_log of physical server this request (check host is IP not domain). So, this request can not send to VPS-3

See: