HAProxy redirect based on path?

北慕城南 提交于 2019-12-06 07:59:36

You should use acl to match you criteria.

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 }

This one should do the trick

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: Change the SSL cert path on your app.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!