I am exploring the use of HAProxy as a balancer in front of a set of web apis that run on IIS.
We are currently using Host Headers to correctly resolve the right web application on IIS. For example, we may have otherapp.mycompany.com running on the same server/port, but using Host Headers IIS knows which one to serve up.
My initial attempt at HAProxy left me with 404 errors, because I was not including the host headers in my request, and so IIS was serving back the default site bound to the given IP, and not resolving by host name.
The fix left me with something like this:
frontend localnodes bind *:80 mode http default_backend nodes backend nodes mode http balance roundrobin option forwardfor reqirep ^Host: Host:\ node1.myapp.mycompany.com server web01 node1.myapp.mycompany.com:80
This works great for a single backend, but I am left scracthing my head on how to include the correct host headers depending on which backend is serving up the request:
backend nodes mode http balance roundrobin option forwardfor reqirep ^Host: Host:\ node1.myapp.mycompany.com server web01 node1.myapp.mycompany.com:80 server web02 node2.myapp.mycompany.com:80
The above does not work whenever
node2 is used because it doesn't resolve correctly in IIS (node2 in this case is on a different server, and therefore different IP. In fact, if they were running on the same server/ip I suspect the request work "work", but they would all be served by node1 per the host header).
- Is it possible to set the host based on the url of the backend used to serve up the request?
- If so, this implies my
checks also need to provide the correct host header based on backend, how would that be done?
Edit: Am using HA-Proxy version 1.7.9 2017/08/18
Let me give this just a little more background. We used to have just
myapp.mycompany.com serving up api requests. We need to expand it. Our clients will still call
myapp.mycompany.com, but that will just point to the HAProxy, which will balance it out to
node2.myapp.mycompany.com. Our current server configurations have us binding a single IP address on each server, so we use host headers to resolve.