大网数据广告活动
服务器运维问答

Nginx limit_req_zone ignores rate value

· 52CE 我爱测

I have a strange behavior my config looks something like this: http { limit_req_zone $binary_remote_addr zone=nocachelimit:10m rate=120r/m; } ... location "/api" { { limit_req zone=nocachelimit burst=20; } } Regardless of what va…

问题原文

原帖链接 · gries · CC BY-SA 3.0

I have a strange behavior my config looks something like this:

http {
    limit_req_zone $binary_remote_addr zone=nocachelimit:10m rate=120r/m;
}
...
location "/api" {
    {
        limit_req zone=nocachelimit burst=20;
    }
}

Regardless of what values i put into the rate, I even tried 1000r/s I keep getting log entries for "normal" users that say:

 [warn] 16526#0: *4661 delaying request, excess: 1.000, by zone "nocachelimit"

The typical usecase is a Pageload that does not fall into the zone + 4-5 Ajax requests that will should be limited to the zone.

What could be the cause for this kind of behavior.

已采纳解答

原帖链接 · Mark Woon · CC BY-SA 3.0

The rate determines how fast requests are processed. If you set the rate to 120r/m, that means 1 request will get processed every 0.5 seconds.

If you get 5 requests all at once, it doesn't mean that they'll all go through. They'll get queued up (up to your burst size), and get processed sequentially, 1 every 0.5 seconds.

You're getting that warning because things are going into the queue and getting delayed. It does not mean that they're getting rejected.

If you don't want things getting delayed, then use the nodelay parameter:

location "/api" {
  limit_req zone=nocachelimit burst=20 nodelay;
}

For more details on exactly how this works, see https://www.nginx.com/blog/rate-limiting-nginx/

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。