【问题标题】:HAProxy - Rewriting URL's transparentlyHAProxy - 透明地重写 URL
【发布时间】:2019-05-23 11:19:08
【问题描述】:

我需要为项目实施 URL 重写操作。这必须使用 HAProxy-1.5 来完成,因为它是在 PfSense 防火墙上实现的,并且目前还没有更高版本。

我有以下网址: update.domain.com 存储库.domain.com 它们都指向同一个后端 server1。现在的挑战是移动文档根: - update.domain.com >> /some/path/repo1。 - repository.domian.com >> /some/path/repo2

不仅文档根被移动,而且由于 TMG 服务器的早期实现存在指向如下文件的链接: update.domain.com/file1.txt

我尝试在前端使用 http-request set-path 和一些 ACL,但不幸的是,此功能适用于 > haproxy-1.6

frontend www
 bind *:80 
 acl    update_url  hdr_beg(host) -m beg update.domain.com 
 acl    update_root path_beg /some/path/repo1/
 http-request set-header /some/path/repo1/%[path] if !update_root update_url    
 use_backend testServer if update_root update_url
 default_backend testServer 

无法更改指向 update.domain.com/file1.txt 等文件的链接。保留 TMG 不是解决方案。我怎样才能让它与 Haproxy-1.5 一起使用?

【问题讨论】:

    标签: configuration url-rewriting acl haproxy


    【解决方案1】:

    对于 HAProxy 1.5,您可以使用 reqrep,它将请求行(和任何标题行)替换为您在正则表达式中指定的内容,例如:

    reqrep ^([^\ :]*)\ /some/path/repo1/(.*) \1\ /some/path/repo2\2
    

    关于如何使用reqrep的更详细的解释可以找到here

    【讨论】:

      猜你喜欢
      • 2016-08-18
      • 2016-11-04
      • 1970-01-01
      • 2015-10-27
      • 2017-11-06
      • 2015-03-29
      • 2012-12-10
      • 2012-01-02
      • 1970-01-01
      相关资源
      最近更新 更多