首页 文章

基于路径的HAProxy重定向?

提问于
浏览
3

我需要将某些路径重定向到https - frontend secured 这样做的原因是我希望我的Web应用程序的某些部分只允许通过https运行 .

我已经想出了如何通过更改我的HAproxy conf来重定向所有流量,如下所示:

frontend unsecured *:80
      #timeout     client 86400000
      #redirect    prefix http://domain.com code 301

      mode http
      timeout client 120s

但是,如何将其配置为仅重定向我的域上的某些子文件夹?

我想要的是仅重定向以下网址:

http://domain.com/info
http://domain.com/echo
http://domain.com/broadcast
http://domain.com/close
http://domain.com/probe
http://domain.com/cd* (wildcard)

这可能吗?

2 回答

  • 1

    您应该使用acl来匹配您的条件 .

    frontend unsecured *:80
        acl is-unsecure-path01 path_beg /info
        acl is-unsecure-path02 path_beg /echo
        acl is-unsecure-path03 path_beg /broadcast
        acl is-unsecure-path04 path_beg /close
        acl is-unsecure-path05 path_beg /probe
        acl is-unsecure-path06 path_beg /cd
    
        use_backend application-backend if is-unsecure-path01
        use_backend application-backend if is-unsecure-path02
        use_backend application-backend if is-unsecure-path03
        use_backend application-backend if is-unsecure-path04
        use_backend application-backend if is-unsecure-path05
        use_backend application-backend if is-unsecure-path06
    
    backend application-backend
        redirect scheme https if !{ ssl_fc }
    
  • 0

    这个应该做的伎俩

    frontend http
        bind *:80
        acl is-secure path_reg ^\/(info|echo|close|cd.*)
        redirect scheme https code 301 if is-secure !{ ssl_fc }
        use_backend the-app unless is-secure
    
    frontend https
        bind *:443 ssl crt /usr/local/etc/haproxy/ssl
        use_backend the-app
    
    backend the-app
        server account-1 account:80 check
    

    NOTE :更改应用程序上的SSL证书路径 .

相关问题