【问题标题】:HAProxy redirect requests from one port to anotherHAProxy 将请求从一个端口重定向到另一个端口
【发布时间】:2016-01-26 08:49:09
【问题描述】:

我使用的是 HAProxy 1.6 版。

我将如何修改配置以重定向来自以下的请求: 本地主机:8081/myapp

到: 本地主机:8111/myapp

谢谢!

【问题讨论】:

    标签: redirect url-redirection haproxy http-redirect


    【解决方案1】:
    frontend weblb
    bind *:8081
    acl if is_seller url_beg /myapp  
    use_backend sellerserver if is_seller
    
    backend sellerserver
    balance source
    server web1 127.0.0.1:8111 maxconn 1024 weight 3 check inter 2000 rise 2 fall 3
    

    【讨论】:

      【解决方案2】:

      类似:

      listen weblb xxx.xxx.xxx.xxx:8081
      balance leastconn
      mode http
      server web1 127.0.0.1:8111
      

      【讨论】:

        【解决方案3】:

        您可以尝试在 Host 标头上使用 replace-value

        http-request replace-value Host localhost:8081 localhost:8111
        

        这很好,因为它还支持正则表达式:

        http-request replace-value Host (.*):8081 \1:8111
        

        【讨论】:

        • 最优雅的方法。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-12
        • 2021-05-28
        • 2021-11-04
        • 2012-01-22
        • 2017-05-15
        • 2017-07-26
        相关资源
        最近更新 更多