Force HAProxy to lookup DNS for backend server

Solution 1:

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

Solution 2:

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.