17

I have haproxy 1.5.8, it proxies some requests (based on the path) to a third-party we have no control over.

Since the IP of backend server is resolved once at startup, it breaks if the IP change.

If there a workaround for that ? In nginx it's possible to declare an internal variable and have it cached for X seconds. I didn't found a similar solution for HAProxy.

Bastien974
  • 1,896
  • 12
  • 44
  • 62

2 Answers2

27

With the recent release of HAProxy 1.6 there is a solution to your problem. You can now define resolvers and associate these to your backend. IP resolution will then be done at runtime.

resolvers dns
  nameserver public-0  xx.xx.xx.xx:53
  hold valid 1s

frontend http
  bind *:8000
  default_backend site-backend

backend site-backend
  balance leastconn
  server site sub.example.com:80 resolvers dns check inter 1000

StackOverflow discussing this

Link to the corresponding documentation

mana
  • 457
  • 6
  • 11
  • hmmm when I do this and begin refreshing the page, I end up getting a 503 within a minute or so – Paulius Dragunas May 23 '17 at 10:21
  • i had to have multiple duplicate "server" lines https://discourse.haproxy.org/t/trouble-with-dns-resolvers-sticking-to-single-ip-address/146/30 – jamshid Jul 31 '18 at 03:19
1

Unfortunately, it seems like this is still a work in progress.

Have you considered using a separate nginx proxy? So that you forward requests for that backend to an nginx instance, which then does DNS resolution and forwards the request? Not ideak, but may work in a lower traffic environment.

David Hulick
  • 121
  • 8