【发布时间】:2018-07-19 04:55:18
【问题描述】:
我有一个如下的 nginx 配置(省略了一些细节):
http {
map $request_uri $guid {
default "unknown";
~^/out/v\d+/(?P<id>.+?)/.+$ $id;
}
map $http_x_forwarded_for $last_client_ip {
default $http_x_forwarded_for;
~,\s*(?P<last_ip>[\.\d]+?)\s*$ $last_ip;
}
limit_req_zone $guid zone=content:20m rate=500r/s;
limit_req_zone $guid zone=auth:20m rate=100r/s;
server {
location /out/ {
auth_request /auth;
set $request_type "unknown";
proxy_pass $upstream_server;
proxy_cache content_cache;
set $cache_key "${request_path}";
proxy_cache_key $cache_key;
proxy_cache_valid 200 301 302 10s;
#Throttling
limit_req zone=content burst=50 nodelay;
limit_req_status 429;
}
location /auth {
internal;
set $auth_type 1;
proxy_pass_request_body off;
proxy_pass $upstream_server/auth?id=$guid&requestor=$last_client_ip;
proxy_cache auth_cache;
set $auth_cache_key "${guid}|${last_client_ip}";
proxy_cache_key $auth_cache_key;
proxy_cache_valid 200 301 302 5m;
proxy_cache_valid 401 403 404 5m;
#Throttling
limit_req zone=auth burst=50 nodelay;
limit_req_status 429;
}
}
}
/out/ 的请求限制与我预期的一样 - 超过 500r/s 的请求会受到限制。但是,我似乎无法让/auth 节流。
我猜这可能是由于auth_request 和limit_req 之间的一些相互作用,或者可能是因为/auth 请求是子请求。我将不胜感激任何帮助或解释!
【问题讨论】:
标签: nginx nginx-reverse-proxy throttling