【问题标题】:haproxy tcp-request content reject unless Layer 7haproxy tcp-request 内容拒绝,除非第 7 层
【发布时间】:2015-05-24 17:57:58
【问题描述】:

我正在尝试将 HAProxy 配置为拒绝第 4 层上的 HTTP 请求,除非请求使用的 URL 路径以配置的前缀开头。

它在第 7 层上运行良好,但我无法让它在第 4 层上运行。

我尝试了很多组合,但没有任何效果。请在下面找到我期望工作的最小示例:

  • 以 HTTP 模式运行
  • 基于路径前缀构建 ACL
  • 如果该前缀不存在,则在第 4 层拒绝

问题是,无论前缀如何,请求总是被拒绝。

我理解文档的方式,如果没有ACL匹配,默认 行动的过程是允许请求。

因此看起来:

  • 要么我在默认行为上搞错了
  • 无论前缀如何,ACL 始终匹配

但我不太确定,你能帮我解决一下吗?

谢谢!

************************************************************

defaults
    timeout connect 3000
    timeout client  3000
    timeout server  3000

backend bck_static1
    mode http
    server server1 example.com:80 check inter 2s rise 2 fall 2

frontend front_static1

    mode http
    default_backend bck_static1

    acl required_prefix path_beg /hello
    tcp-request content reject unless required_prefix

    option forwardfor
    option httpclose

    bind 0.0.0.0:22334

************************************************************

HA-Proxy version 1.4.24 2013/06/17
HA-Proxy version 1.5.12 2015/05/02

************************************************************

$ haproxy -d -V -f haproxy1.conf
Available polling systems :
     sepoll : pref=400,  test result OK
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result FAILED
Total: 4 (3 usable), will use sepoll.
Using sepoll() as the polling mechanism.


00000000:front_static1.accept(0004)=0005 from [127.0.0.1:53110]
00000000:front_static1.clicls[0005:ffff]
00000000:front_static1.closed[0005:ffff]


00000001:front_static1.accept(0004)=0005 from [127.0.0.1:53112]
00000001:front_static1.clicls[0005:ffff]
00000001:front_static1.closed[0005:ffff]

^C
$ 

************************************************************

$ curl -v 127.0.0.1:22334/abc
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 22334 (#0)
> GET /abc HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:22334
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

************************************************************

$ curl -v localhost:22334/hello
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 22334 (#0)
> GET /hello HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:22334
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
$ 

************************************************************

【问题讨论】:

    标签: haproxy


    【解决方案1】:

    仅供参考 - 在 HAProxy 的邮件列表中已得到答复。

    http://comments.gmane.org/gmane.comp.web.haproxy/21962

    需要添加 tcp-request inspect-delay 以便 HAProxy 有机会检查传入的请求。

    设置tcp-request inspect-delay 10s 效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      • 2017-08-05
      • 1970-01-01
      • 2014-12-12
      相关资源
      最近更新 更多