nginx的limit_req_zone似乎无法正常工作。

我正在尝试使用nginx通过openresty对特定uri设置全局限制。使用以下配置,如果我对此框发出curl,则无论我每分钟请求多少次,我都会得到204回答。 worker_processes 1; error_log logs/error.log;

events {
}

http {
    log_format spec_format '$request_uri $const $status';
    access_log logs/access.log spec_format; #off;
    resolver 10.0.0.2;

    limit_req_log_level error;
    limit_req_zone $const zone=one:100k rate=1r/m;

    server {
        set $const 1;

        listen 80;

        location / {
            return 200 "invalid url";
        }

        location ~* /request/? {
            limit_req zone=one burst=1 nodelay;
            return 204;
        }

        location /health/ {
            return 200 "healthy";
        }
    }
}

从文档中,我找不到任何明显的内容(我尝试过很多切换)。

如果有帮助的话,该框正在AWS上运行,位于EIP后面并运行Ubuntu 13.10。 我使用的是来自openresty.org的openresty-1.5.8.1。

另外,我想要的实际限制是每秒约24000个请求,并且我认为可能会产生冲突的其他设置,但即使剥离了其他设置,它也不会像我认为的那样运作。

点赞
用户291395
用户291395

问题可能是当limit_req_zone处理时$const尚未设置。您在日志中看到了正确的$cost值吗?

limit_req_module忽略空值,根据文档:

关键字是指指定变量的任何非空值(不计算空值)。

2014-08-21 16:35:01