429
nginx
runtime_error
ai_generated
partial
限制请求,拒绝:429 请求过多
limiting requests, reject: 429 Too Many Requests
ID: nginx/limit-req-rejected-request
85%修复率
88%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| nginx 1.24.0 | active | — | — | — |
| nginx 1.22.1 | active | — | — | — |
| nginx 1.20.2 | active | — | — | — |
根因分析
客户端超过了 limit_req_zone 和 limit_req 指令定义的速率限制,导致返回 429 状态码。
English
The client has exceeded the rate limit defined by the limit_req_zone and limit_req directives, resulting in a 429 status code.
官方文档
https://nginx.org/en/docs/http/ngx_http_limit_req_module.html解决方案
-
Increase the rate limit in the http block: 'limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;' and adjust the location block: 'limit_req zone=mylimit burst=20 nodelay;' to allow bursts.
-
Use a larger burst size to absorb temporary spikes: 'limit_req zone=mylimit burst=50 nodelay;' and ensure the zone size is sufficient (e.g., 10m for 160k IPs).
-
Implement client-side retry with exponential backoff to avoid hitting the limit, e.g., in JavaScript with a max retries of 3 and delay doubling.
无效尝试
常见但无效的做法:
-
90% 失败
worker_connections controls concurrent connections, not request frequency.
-
85% 失败
Rate limiting occurs at the request level, not the body reading phase.
-
10% 失败
This removes protection against abuse or DDoS.