Haproxy后端模块使用IP代替域名

时间:2019-06-28 09:21:21

标签: haproxy

我正在尝试在haproxy后端模块配置中使用域名

backend prod_auth
  balance leastconn
  option httpchk GET /auth-service/generalhealthcheck
  http-check expect string "Service is up and reachable"
  server auth-service-1 domain-service.com:8080 check

但是haproxy使用domain-service.com的IP(10.1.122.83)而不是域名本身进行健康检查,这成为一个问题,因为我的服务使用的是域名而不是IP。

root@ram:~$ curl http://domain-service.com/auth-service/generalhealthcheck
["Service is up and reachable"]

root@ram:~$ curl http://10.1.122.83/auth-service/generalhealthcheck
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>

我无法使我的服务在IP上运行,因为同一台服务器上正在运行多个其他服务,并且使用不同的域名(rDNS)。

我不知道为什么haproxy使用IP而不是域名,我使用WireShark进行了验证。有什么方法可以强制haproxy使用后端模块中提到的域名?

我尝试在/ etc / hosts中进行设置,但这不起作用

domain-service.com domain-service.com

我正在使用HA-Proxy版本1.7.8 2017/07/07

1 个答案:

答案 0 :(得分:0)

您可以使用以下相同的Host自定义发送到您域的option httpchk标头:

backend domain-service-backend
   mode http
   option httpchk GET /get HTTP/1.1\r\nHost:\ domain-service.com