How can I set up HAProxy to a backend based on a value in the url?

对着背影说爱祢 提交于 2019-12-21 23:57:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!