I am working on an application that consists of multiple services that, in production, run on different servers. In development, they run as multiple sites with different ports on the same machine. I would like to be able to use a hostname to locate the services, and have HAProxy do the port mapping to a dynamic backend host/port. I have a wildcard DNS mapping for the domain, resolving to the HAProxy IP.
For example, http://serviceA-myhost.domain.com/ would map to http://myhost:8080, http://serviceB-myotherhost.domain.com/ would map to http://myotherhost:8081, and so on. I can write these rules in HAProxy, but I would like to use regular expressions to get the host and service, then use the extracted host for the backend, with a port determined by the value of the service. That way I don't need to set up a frontend/backend for each dev machine.
Is this possible to do? I've seen examples of using a regular expression, but the service name to port has me stumped.
Thanks, Erick
来源:https://stackoverflow.com/questions/34079846/how-can-i-set-up-haproxy-to-a-backend-based-on-a-value-in-the-url