如何定义"limit_req_zone"



我正在使用nginx ingress控制器(这与ingress nginx不同(

我有这个入口文件

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-test"
acme.cert-manager.io/http01-edit-in-place: "true"
nginx.org/location-snippets: |
limit_req zone=by_web;
spec:
ingressClassName: nginx
rules:
- host: my.domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
tls:
- hosts:
- my.domain.com
secretName: quickstart-example-tls

我能够使用nginx.org/location-snippets定义limit_req

如何定义limit_req_zone

limit_req_zone $request_uri zone=by_web:10m rate=60r/m;

谨致问候。

根据官方文档中的这篇文章,您可以通过向location-snippetsserver-snippets注释添加以下ConfigMap键来定义limit_req_zone

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-test"
acme.cert-manager.io/http01-edit-in-place: "true"
nginx.org/location-snippets: |
geo $limit {
default 1;
10.0.0.0/8 0;
192.168.0.0/24 0;
}
map $limit $request_uri {
default '';
'1'     $binary_remote_addr; 
}
limit_req_zone $request_uri zone=by_web:10m rate=1r/s;
nginx.org/server-snippets: |
location / {
limit_req zone=by_web burst=10 nodelay;
}
spec:
ingressClassName: nginx
rules:
- host: my.domain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
tls:
- hosts:
- my.domain.com
secretName: quickstart-example-tls

因此,这将允许您对不在"允许列表"上的任何人的请求定义费率限制

相关内容

  • 没有找到相关文章

最新更新