小编Jin*_*nKo的帖子

Nginx:速率限制失败基本身份验证尝试

在 Nginx(撰写本文时为 1.14.1)中给出一个简单的 HTTP 基本身份验证设置,如下所示:

server {
  ...
  location / {
    auth basic "HTTP Auth Required";
    auth basic user file "/path/to/htpasswd";
  }
}
Run Code Online (Sandbox Code Playgroud)

...如何对失败的登录尝试应用速率限制?例如,如果 30 秒内有 10 次登录尝试失败,我想阻止该源 IP 在一个小时内访问该网站。我希望利用limit_req_zone和 相关指令,但找不到一种方法来连接请求的身份验证状态。

这在 HAproxy 中相当简单,使用棒表和 ACL,使用类似以下工作示例的内容。

userlist users
  user me password s3cr3t

frontend https.local
  ...

  # Set up the stick table to track our source IPs, both IPv4 & IPv6
  stick-table  type ipv6  size 100k  expire 1h  store http_req_rate(30s)

  # Check if the user has authenticated
  acl  auth_ok  http_auth(users) …
Run Code Online (Sandbox Code Playgroud)

nginx authentication brute-force-attacks rate-limiting

5
推荐指数
1
解决办法
1594
查看次数