【问题标题】:nginx limit_req_zone doesn't seem to worknginx limit_req_zone 似乎不起作用
【发布时间】:2014-08-22 00:35:01
【问题描述】:

我正在尝试通过 openresty 使用 nginx 为某个 uri 设置全局限制

使用以下配置,如果我卷曲此框,无论我每分钟请求多少次,我都会得到 204。 worker_processes 1; error_log 日志/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";
        }
    }
}

从文档中我找不到任何明显的东西(我尝试过很多次切换)。

如果有帮助,该机器在 EIP 和 Ubuntu 13.10 后面的 AWS 上运行。我正在使用来自 openresty.org 的 openresty-1.5.8.1。

另外,我想要工作的实际限制是大约 24000r/s,并且我认为还有其他设置可能会发生冲突,但即使将其剥离也不会像我认为的那样运行。

【问题讨论】:

    标签: nginx


    【解决方案1】:

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

    limit_req_module 将ignore empty values,来自文档:

    key是指定变量的任意非空值(空值 不计入)。

    【讨论】:

      猜你喜欢
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 2016-02-01
      • 2020-09-23
      • 2010-12-05
      • 2011-06-14
      • 2015-01-10
      相关资源
      最近更新 更多