# Help me to configurations backend with proxy server

**URL:** <https://discourse.haproxy.org/t/help-me-to-configurations-backend-with-proxy-server/4138>\
**Category:** Help!\
**Created:** [August 2, 2019, 9:01am UTC](https://discourse.haproxy.org/t/help-me-to-configurations-backend-with-proxy-server/4138 "2019-08-02T09:01:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tu.vu](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tu.vu](https://discourse.haproxy.org/u/tu.vu)\
**Post date:** [August 2, 2019, 9:01am UTC](https://discourse.haproxy.org/t/help-me-to-configurations-backend-with-proxy-server/4138/1 "2019-08-02T09:01:58Z")

</div>

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:**

```auto
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**

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [August 5, 2019, 12:38pm UTC](https://discourse.haproxy.org/t/help-me-to-configurations-backend-with-proxy-server/4138/2 "2019-08-05T12:38:37Z")

</div>

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](https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#option%20httpchk)

> [@tu.vu](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![tu.vu](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tu.vu](https://discourse.haproxy.org/u/tu.vu)\
**Post date:** [August 6, 2019, 7:26am UTC](https://discourse.haproxy.org/t/help-me-to-configurations-backend-with-proxy-server/4138/3 "2019-08-06T07:26:15Z")

</div>

Hi [lukastribus](https://discourse.haproxy.org/u/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

```auto
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

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [August 6, 2019, 7:54am UTC](https://discourse.haproxy.org/t/help-me-to-configurations-backend-with-proxy-server/4138/4 "2019-08-06T07:54:58Z")

</div>

See:

> [@Helathcheck on multiple backends with virtual hostnames](https://discourse.haproxy.org/t/helathcheck-on-multiple-backends-with-virtual-hostnames/2413):
>
> I have 2 backends which are running on two different virtual host names and need to perform healthchecks on them to loadbalance the traffic. issue is : only the last healthcheck (prd03) works , not prd02. How I can do healthcheck against 2 virtual hostnames? here is my config: backend xxxx.searchCustomer mode http balance roundrobin option httpchk GET /env HTTP/1.1\r\nHost:\ [customerlookup.xxx.px-prd02.cf.xxxx.com:443](http://customerlookup.xxx.px-prd02.cf.xxxx.com:443)\r\n option httpchk GET /env HTTP/1.1\r\nHost:\ [customerlookup.xxx.px-p…](http://customerlookup.xxx.px-prd03.cf.xxxx.com:443)

> [@Send real Host header in httpchk requests](https://discourse.haproxy.org/t/send-real-host-header-in-httpchk-requests/3073):
>
> Hi, folks! Is there is a way to send real backend address as a Host header in the httpchk requests? We are currently using HTTP 1.0, but would like to switch to HTTP 1.1 and sending meaningful Host header is a mast in your case. Here is our current backend section of the config: backend apiservers balance leastconn mode http option httpchk GET /healthz HTTP/1.0\r\nAuthorization:\ Bearer\ SOME\_TOKEN\_HERE http-check disable…
