4

我正在使用带有 stunnel 处理 SSL 的 haproxy(并使用代理模式来保留来自 haproxy 的原始 IP)。

我有几个 acl 测试根据域、标头或路径重定向到不同的后端。

问题是无论您是通过 http 还是 https 进入,这些都是相同的,但我必须在配置中复制它们。有什么办法可以减少重复?

这是一个示例配置:

global
    user haproxy
    group haproxy
    #etc...

frontend http-in
    bind *:80

    acl files_path path_beg /files/
    acl beta_host hdr_beg(host) -i beta.

    use_backend files if files_path
    use backend beta_host
    default_backend appservers

frontend https-in
    bind *:442 accept-proxy

    acl files_path path_beg /files/
    acl beta_host hdr_beg(host) -i beta.

    use_backend files if files_path
    use backend beta_host
    default_backend appservers


backend appservers
    balance roundrobin
    option forwardfor

    server appserver_1 localhost:8080 weight 1
    server appserver_2 192.168.1.101:8080 weight 1

backend files
    balance roundrobin
    option forwardfor
    server file1 192.168.1.102 weight 1
    server file2 192.168.1.103 weight 1

backend beta
    balance roundrobin
    server beta1 192.168.1.104 weight 1

http-in 和 https-in 有不同的端口,并且 https-in 必须 sepcify accept-proxy 以便 stunnel 可以使用代理协议将用户的原始 IP 传递给它。但除此之外,它们是相同的,并且应该始终相同。有没有办法减少这种重复?(haproxy 1.5-dev)

4

2 回答 2

4

您可以简单地将前端中的一个 http 绑定到两者。

frontend http-in
  bind *:80
  bind 0.0.0.0:443 transparent
于 2015-01-25T11:23:05.007 回答
1

不幸的是,haproxy 手册(http://haproxy.1wt.eu/download/1.5/doc/configuration.txt)仍然认为 acl 只能在前端、监听和后端部分定义。

如果 https 和 http 前端相同,可以在一个前端定义几个绑定语句。

于 2014-04-07T15:07:24.367 回答