HAProxy URL重写

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HAProxy URL重写相关的知识,希望对你有一定的参考价值。

In this example:

*rewrite urls from domain.com to www.domain.com*

This is somewhat documented elsewhere, but not very well, so here's an example on how to perform simple URL rewriting with HAProxy (instead of using mod_rewrite with apache).

This works great if your servers use lighttpd, nginx, or anything that doesnt provide its own simple url rewriting.
  1. frontend webserver
  2. bind :80
  3. mode http
  4. acl is_www hdr_beg(host) -i www.domain.com
  5. use_backend http_cluster if is_www
  6. default_backend http_redir
  7.  
  8. backend http_redir
  9. mode http
  10. balance source
  11. option nolinger
  12. server web 127.0.0.1:8080 redir http://www.domain.com
  13.  
  14. backend http_cluster
  15. mode http
  16. option forwardfor
  17. balance source
  18. option httpclose
  19. option httpchk HEAD / HTTP/1.0
  20. server web01 172.16.0.11:80 weight 1 check inter 1000 rise 5 fall 1
  21. server web02 172.16.0.12:80 weight 1 check inter 1000 rise 5 fall 1
  22. server web03 172.16.0.13:80 weight 1 check inter 1000 rise 5 fall 1
  23. server web04 172.16.0.14:80 weight 1 check inter 1000 rise 5 fall 1

以上是关于HAProxy URL重写的主要内容,如果未能解决你的问题,请参考以下文章

Haproxy配置之URL重写,支持websocket

sh Unbounce脚本片段,用于在零停机时间内重新启动HAProxy

VSCode自定义代码片段3——url大全

VSCode自定义代码片段3——url大全

VSCode自定义代码片段3——url大全

需要在 .htaccess 重写规则中转义 # (hash/pound) 字符