Nginx Rate Limit 即使未超过限制也会阻止连接

Nginx Rate Limit 即使未超过限制也会阻止连接

我们正在尝试使用 Nginx 作为负载平衡的服务器,出于安全原因,我们决定应用本机速率限制功能,对其进行配置,以便当每秒有超过 200 个请求时,用户的请求会被阻止。

当用户达到限制时,我们使用下面的设置来配置此块。

limit_req_zone $binary_remote_addr zone=one:10m rate=200r/s;
limit_req zone=one burst=20;

实际情况是,即使用户在第一次访问时发出了 97 个 AJAX 请求,Nginx 也会阻止这些请求,如下面的日志所示:

2022/07/19 11:10:37 [error] 8494#8494: *1698 limiting requests, excess: 20.600 by zone "one", client: [USER-IP], server: example.com, request: "GET /views/components/page-1.html HTTP/1.1", host: "example.com", referrer: "https://example.com/dash.html"
2022/07/19 11:10:37 [error] 8495#8495: *1699 limiting requests, excess: 20.600 by zone "one", client: [USER-IP], server: example.com, request: "GET /views/components/page-2.html HTTP/1.1", host: "example.com", referrer: "https://example.com/dash.html"
2022/07/19 11:10:37 [error] 8495#8495: *1702 limiting requests, excess: 20.800 by zone "one", client: [USER-IP], server: example.com, request: "GET /views/components/page-3.html HTTP/1.1", host: "example.com", referrer: "https://example.com/dash.html"

什么可能配置错误?我们该如何修复它?

相关内容