【问题标题】:How can I close haproxy frontend connections coming from unknown hosts?如何关闭来自未知主机的 haproxy 前端连接?
【发布时间】:2019-10-23 08:35:12
【问题描述】:

现在我正在使用 nginx 关闭来自未知主机的连接并返回 444“无响应”

如何使用 nginx 前面的 haproxy 实现相同的效果(节省 haproxy 和 nginx 之间的额外步骤)

当前 nginx 配置:

server {
  # Close connection for unrecognized hosts (444 no response)
  listen 80 default_server;
  listen [::]:80 default_server;

  return 444;
}

【问题讨论】:

    标签: haproxy no-response


    【解决方案1】:

    Ejez 您可以接受来自已知 ip 的连接是 haproxy 前端特定 ip 的块连接。

    参考代码:

    • 允许的已知 ip
    acl network_allowed src 20.30.40.50 20.30.40.40
    use_backend allowed_backend if network_allowed
    

    • 仅阻止某些 ip
    acl is-blocked-ip src 192.0.2.11 192.0.2.12 192.0.2.18
    http-request deny if is-blocked-ip
    

    参考:

    【讨论】:

    • 感谢@rangeesh 的回复。但是我不想向客户端发送“403 禁止”响应(使用“拒绝”),而是不想发送任何内容并关闭 haproxy 端的连接并保持客户端挂起,这样机器人就会变慢下降了很多。我找到了实现这一目标的“静滴”。参考:haproxy.com/blog/introduction-to-haproxy-acls/…
    【解决方案2】:

    这可以使用“silent-drop”来实现

    acl host_example req.hdr(host) -i example.com
    http-request silent-drop if not host_example
    

    https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-request%20silent-drop https://www.haproxy.com/blog/introduction-to-haproxy-acls/#using-acls-to-block-requests

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 2016-04-26
      相关资源
      最近更新 更多