HAProxy 可以用来重写漂亮的 URL 吗?

HAProxy 可以用来重写漂亮的 URL 吗?

当 HAProxy 将请求传递给 Web 服务器时,它可以将 URI 从“domain.com/cool/url”重写为“domain.com/index.php/cool/url”吗?

谢谢。

答案1

reqrep  <search> <string>
reqirep <search> <string>   (ignore case)
  Replace a regular expression with a string in an HTTP request line
  May be used in sections :   defaults | frontend | listen | backend
                                 no    |    yes   |   yes  |   yes
  Arguments :
    <search>  is the regular expression applied to HTTP headers and to the
              request line. This is an extended regular expression. Parenthesis
              grouping is supported and no preliminary backslash is required.
              Any space or known delimiter must be escaped using a backslash
              ('\'). The pattern applies to a full line at a time. The "reqrep"
              keyword strictly matches case while "reqirep" ignores case.

    <string>  is the complete line to be added. Any space or known delimiter
              must be escaped using a backslash ('\'). References to matched
              pattern groups are possible using the common \N form, with N
              being a single digit between 0 and 9. Please refer to section
              6 about HTTP header manipulation for more information.

HAProxy 1.3 文档


编辑:是否使用 HAProxy 实现重写(显然)取决于你,但我强烈建议你考虑使用mod_rewrite(或类似)来代替。

HAProxy 的重写功能旨在促进负载平衡活动,从维护的角度来看,Web 服务器行为不应该与负载平衡器配置耦合 - 即,如果要从托管配置中删除负载平衡器,则单个 Web 服务器应该对于给定 URI 的请求,以相同的内容(而不是 404 错误)进行响应。

相关内容