小编Way*_*ong的帖子

为什么在 Nginx 中使用 return 指令时速率限制不起作用?

我有以下 nginx 配置:

\n
worker_processes 1;\nerror_log logs/error.log;\nevents {\n   worker_connections 1024;\n}\nhttp {\n   limit_req_zone $request_uri zone=by_uri_6000:10m rate=6000r/s;\n\n   server {\n      listen 80;\n      server_name "openresty.com";\n\n      location = /limit-6000 {\n         limit_req zone=by_uri_6000 nodelay;\n         return 200 "ok"\n      }\n   }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但使用wrk测试时根本不起作用:

\n
wrk -c100 -t10 -d5s http://localhost/limit-6000\nRunning 5s test @ http://localhost/\n  10 threads and 100 connections\n  Thread Stats   Avg      Stdev     Max   +/- Stdev\n    Latency     5.57ms    1.65ms  23.47ms   81.17%\n    Req/Sec     1.81k   495.91     9.27k    99.60%\n  90400 requests in 5.10s, 17.93MB read\nRequests/sec:  17713.29\nTransfer/sec:      3.51MB\n
Run Code Online (Sandbox Code Playgroud)\n

但是,如果我将配置更改为如下所示(实际上我正在使用 openresty):

\n
      location …
Run Code Online (Sandbox Code Playgroud)

nginx openresty

3
推荐指数
1
解决办法
721
查看次数

标签 统计

nginx ×1

openresty ×1