Dynamic routing to backend based on context path in HAProxy

十年热恋 提交于 2019-12-24 09:29:28

问题


I have specific requirement that depending on my context path I have to redirect my traffic to different server/port though HAProxy. I have already achieved the same with "path_beg" in ACL. Below is the configuration.

use_backend a1 if { path_beg /a1 }
use_backend a2 if { path_beg /a2 }

backend a1
        balance roundrobin
        server 1-www 172.17.0.1:80 check cookie s2

backend a2
        balance roundrobin
        server 1-www 172.17.0.3:80 check cookie s2

Now the concern is here every context path I also need to enter a frontend settings like use_backend a1 if { path_beg /a1 } which I would like to avoid. What I want when I need to add a new server I will add the backend as it's necessary but for the front end I am looking for something like this.

use_backend regex

Where regular expression will take the context path from the url and will proceed to the corresponding backend.

Note: backend name will be same as context path. Like if the url is http://example.com/dummy then backend name will be "dummy".

Any suggetion on the same.

来源:https://stackoverflow.com/questions/40676915/dynamic-routing-to-backend-based-on-context-path-in-haproxy

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