haproxy将URL路径重定向到另一个路径

时间:2019-01-25 19:23:13

标签: path url-redirection haproxy

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路径中有两个与示例不同的部分,所以我很困惑。

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以声明一个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

相关问题