【问题标题】:haproxy redirect URL path to another pathhaproxy 将 URL 路径重定向到另一个路径
【发布时间】:2019-01-25 19:23:13
【问题描述】:

haproxy 版本 1.5.18

我要重定向:

/document/(.*)/(.*)/somefile => /anotherPath/somefile

例如:重定向

 /document/20181/20182/a_good_pic.jpg => /anotherPath/a_good_pic.jpg

如何用 haproxy 做到这一点?

我重试了 reqirep 的示例,例如:

# replace "/static/" with "/" at the beginning of any request path.
reqrep ^([^\ :]*)\ /static/(.*)     \1\ /\2

但我的示例在 URL 路径中有两个部分与示例不同,所以我很困惑。

谢谢!

【问题讨论】:

  • 请不要将问题交叉发布到多个站点。 serverfault.com/q/950831/153161
  • 您使用 HAProxy 1.5 有什么原因吗?它目前只接收关键补丁,而不是长期支持的一部分。使用 1.6 或更高版本将使您尝试做的事情变得更加容易。
  • 是的,通常版本由IT人员决定,我们无权升级。

标签: path url-redirection haproxy


【解决方案1】:

您可以声明一个 acl,然后执行一个有条件的 use_backend 语句。像这样:

frontend a-frontend-conf

    # Declare an ACL using path_beg (Path Begins)
    acl path_images path_beg /images

    # Use backend server1 if acl condition path_images is fulfilled
    use_backend server1 if path_images

backend server1
    [...]

来源:https://serverfault.com/questions/659793/haproxy-how-to-balance-traffic-within-directory-reached

【讨论】:

  • 是的,但 some_path 部分可以是任何字符串。所以不能使用acl来定义条件检查。
  • 对于该实例,您将使用带有 -m reg 选项的 ACL,并使用正则表达式来弥补这一点。请参阅:serverfault.com/questions/388937/… 有关使用通配符的 ACL 的更多信息。
猜你喜欢
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
  • 2019-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-12
相关资源
最近更新 更多