HAProxy重定向基于路径? [英] HAProxy redirect based on path?

查看:249
本文介绍了HAProxy重定向基于路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to redirect certain paths to https - frontend secured The reason for this is that i want certain parts of my web application to only be allowed to run over https.

我想出了如何通过更改HAproxy conf来重定向所有流量的方法:

I've figured out how to redirect all traffic by changing my HAproxy conf like this:

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

      mode http
      timeout client 120s

但是如何配置它以仅重定向域中的某些子文件夹?

But how can i configure it to only redirect certain sub-folder on my domain?

我只想重定向以下URL:

What i would like is to redirect only the following URLs:

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)

这可能吗?

推荐答案

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

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 }

这篇关于HAProxy重定向基于路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆