Posted By

alexwilliams on 08/13/09


Tagged

url apache rewriting haproxy


Versions (?)

HAProxy URL Rewriting


 / Published in: Apache
 

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

Report this snippet  

You need to login to post a comment.