El *_*rto 2 http nginx rate-limiting
我正在尝试设置 Nginx limit_req 模块来限制任何 IP 对同一 URL 的请求速率。
我想定义一个limit_req_zone由客户端 IP 和请求 URI 组合而成的密钥。也就是说,代替这个:
limit_req_zone $binary_remote_addr zone=req_dev:10m rate=2r/s;
像这样的东西:
set $ip_url "$binary_remote_addr$request_uri"
limit_req_zone $ip_url zone=req_dev:10m rate=2r/s;
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为set无法在上下文中调用http:
nginx: [emerg] "set" directive is not allowed here in /etc/nginx/nginx.conf:47
Run Code Online (Sandbox Code Playgroud)
有什么办法可以实现这一点吗?
需要明确的是:我不想限制特定 URL 的速率。我想避免一个 IP 每秒访问同一 URL 两次以上。
您可以将密钥设置为您想要的任何内容limit_req_zone。
limit_req_zone "$binary_remote_addr$request_uri" zone=req_dev:10m rate=2r/s;
Run Code Online (Sandbox Code Playgroud)
请注意,这至少需要 nginx 1.7.6。