You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HAProxy path_beg规则无法跳转,如何配置ACL与use_backend?

HAProxy /test路径跳转配置修改方案

问题根源

当前配置中default_backend放在了所有use_backend规则之前,HAProxy会直接启用默认后端,导致匹配/test路径的规则无法触发。

修改步骤

  1. 调整规则顺序:将default_backend移到所有use_backend规则之后,确保路径匹配规则优先被检查
  2. (可选)优化路径匹配逻辑:如果仅需精确匹配/test路径(而非所有以/test开头的请求),将path_beg替换为path_exact

修改后的完整配置

global
    daemon

defaults
    mode               http

frontend  http-in
    bind *:80
    acl url path_beg -i /test
    acl chrome hdr_sub(User-Agent) Chrome
    acl safari  hdr_sub(User-Agent) Safari
    use_backend bk_url if url
    use_backend bk_chrome if chrome
    use_backend bk_safari if safari
    default_backend    backend_servers
backend backend_servers
    balance            roundrobin
    server             web 10.31.0.100:80 cookie w1 check
    server             web01 10.31.0.104:80 cookie w2 check
    server             ns 10.31.0.103:80 cookie w3 check
backend bk_url
    server             web   10.31.0.100:80
backend bk_chrome
    server             web01 10.31.0.104:80
backend bk_safari
    server             ns    10.31.0.103:80

关键说明

  • 规则执行顺序:HAProxy按从上到下的顺序检查use_backend规则,匹配到第一个符合条件的规则后立即跳转对应后端,default_backend仅在所有规则都不匹配时生效
  • 路径匹配选项:
    • path_beg -i /test:匹配所有以/test开头的请求(如/test、/test/page等)
    • path_exact -i /test:仅精确匹配/test路径

内容的提问来源于stack exchange,提问作者hhh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 04:52:54