在Ubuntu 14.04上使用haproxy版本1.4.24
我想使用haproxy来重写和redirect不再有效的新的等效url。 我已经使用haproxy作为反向代理和负载均衡器。 我有重写工作正常,但是当我尝试redirect我最终没有redirect或在redirect循环。 我读了几个地方,这个技术是重写和redirect的前缀在前端的URL,但我没有任何运气。 任何帮助,将不胜感激。 谢谢。
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 4096 user haproxy group haproxy spread-checks 0 defaults log global mode http option httplog option dontlognull retries 3 timeout queue 20000 timeout client 50000 timeout connect 5000 timeout server 50000 frontend haproxy-0-80 bind 0.0.0.0:80 default_backend haproxy_service acl old_url path_beg -i /post # The below doesn't appear to have any effect reqrep ^([^\ :]*)\ /post/\d+/(.+)/? \1\ /\2 redirect prefix http://10.0.3.10 code 301 if old_url backend haproxy_service balance leastconn cookie SRVNAME insert # The below properly handles the rewrite reqrep ^([^\ :]*)\ /post/\d+/(.+)/? \1\ /\2 server ghost-0-2368 10.0.3.220:2368 maxconn 100 cookie S0 check
事实certificate,我非常接近一个工作configuration。
redirect prefix / code 301 if old_url使其正常工作, redirect prefix / code 301 if old_url更改redirect行以读取redirect prefix / code 301 if old_url 。
我写了一篇博客文章,详细介绍了这个问题: https : //fromanegg.com/post/2014/12/05/how-to-rewrite-and-redirect-with-haproxy/