【问题标题】:How to redirect url using haproxy如何使用 haproxy 重定向 url
【发布时间】:2018-07-13 00:18:14
【问题描述】:

我想使用 haproxy 将 https://myserver/myapplication/ 重定向到 https://myserver.domain.com/myapplication/

这是我的 haproxy 配置

frontend LB_http
   bind 10.123.122.112:80
   reqadd X-Forwarded-Proto:\ http
   default_backend LB


frontend LB_https
   bind 10.123.122.112:443 ssl crt /usr/local/apache2/conf/server.pem
   reqadd X-Forwarded-Proto:\ https
   default_backend LB

backend LB
   redirect scheme https if !{ ssl_fc }
   mode http
   stats enable
   stats hide-version
   stats uri /stats
   stats realm Haproxy\ Statistics
   stats auth haproxy:redhat            # Credentials for HAProxy Statistic report page.
   balance roundrobin                   # Load balancing will work in round-robin process.
   option httpchk
   option httpclose
   option forwardfor

   server myserver.domain.com myserver.domain.com:80          # backend server.

我已经通过添加以下两行来编辑配置文件

acl no_domain hdr(host) -i myserver
http-request redirect code 301 prefix %[hdr(host)].domain.com%[path] if no_domain

但是现在,当我尝试时

我的服务器/我的应用程序/

我猜该网址多次重定向。它正在将我重定向到像这样的很长的 url

https://myserver/myapplication/myserver.domain.com/myapplication/myserver.domain.com/myapplication/myserver.domain.com/myapplication/myserver.domain.com/myapplication/myserver.domain.com/myapplication/myserver.domain.com/myapplication/

我错过了什么?

【问题讨论】:

    标签: apache .htaccess https haproxy httpd.conf


    【解决方案1】:

    我已经修改了如下代码,它开始按预期工作

    frontend LB_http
       bind 10.123.122.112:80
       reqadd X-Forwarded-Proto:\ http
       default_backend LB
    
    
    frontend LB_https
       bind 10.123.122.112:443 ssl crt /usr/local/apache2/conf/server.pem
       reqadd X-Forwarded-Proto:\ https
       default_backend LB
    
    backend LB
       acl no_domain hdr(host) -i myserver
       http-request redirect code 301 prefix https:\/\/myserver.domain.com if no_domain
       redirect scheme https if !{ ssl_fc }
       mode http
       stats enable
       stats hide-version
       stats uri /stats
       stats realm Haproxy\ Statistics
       stats auth haproxy:redhat            # Credentials for HAProxy Statistic report page.
       balance roundrobin                   # Load balancing will work in round-robin process.
       option httpchk
       option httpclose
       option forwardfor
    
       server myserver.domain.com myserver.domain.com:80          # backend server.
    

    现在当我给

    我的服务器/我的应用程序

    它重定向到

    https://myserver.domain.com/myapplication

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 2018-08-25
      • 1970-01-01
      • 2015-10-27
      • 2012-12-10
      • 2013-11-07
      • 1970-01-01
      • 2013-10-27
      • 2016-09-20
      相关资源
      最近更新 更多