我正在尝试为limit_reqKubernetes ingress-nginx 中的特定路径设置速率限制选项,以防止强制身份验证。
我已经limit_req_zone使用 ConfigMap定义了:
http-snippet: |
limit_req_zone $the_real_ip zone=authentication_ratelimit:10m rate=1r/s;
Run Code Online (Sandbox Code Playgroud)
接下来,我使用注解添加自定义位置块:
nginx.ingress.kubernetes.io/configuration-snippet: |
location ~* "^/authenticate$" {
limit_req zone=authentication_ratelimit nodelay;
more_set_headers "x-test: matched";
}
Run Code Online (Sandbox Code Playgroud)
这会产生 nginx.conf:
server {
# - - 8< - -
location / {
# - - 8< - -
location ~* "^/authenticate$" {
limit_req zone=authentication_ratelimit nodelay;
more_set_headers "x-test: matched";
}
proxy_pass http://upstream_balancer;
proxy_redirect off;
}
Run Code Online (Sandbox Code Playgroud)
结果是/authenticate总是返回 HTTP 503(带有 x-test 标头)。来自入口访问日志的消息:
<ip> - [<ip>] - - [04/Jan/2019:15:22:07 +0000] "POST /authenticate …Run Code Online (Sandbox Code Playgroud)