使用 haproxy 重定向重写的 url

hat*_*tch 6 ubuntu haproxy

在 Ubuntu 14.04 上使用 haproxy 版本 1.4.24

我想使用 haproxy 来重写和重定向不再有效的 URL。我已经在使用 haproxy 作为反向代理和负载均衡器。我的重写工作正常,但是当我尝试重定向时,我要么没有重定向,要么进入重定向循环。我在几个地方读到过,一种技术是在前端使用前缀重写和重定向 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
Run Code Online (Sandbox Code Playgroud)

hat*_*tch 8

事实证明,我非常接近工作配置。

将重定向行更改为 readredirect prefix / code 301 if old_url使其按预期工作。

我写了一篇博文,更详细地概述了这个问题:https : //fromanegg.com/post/2014/12/05/how-to-rewrite-and-redirect-with-haproxy/