voi*_*urn 2 kubernetes kubernetes-helm kubernetes-ingress nginx-ingress
我有以下 ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-configuration-snippet
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/server-snippet: |
location /base/path/v1/api/update {
deny all;
return 404;
}
spec:
rules:
- http:
paths:
- path: /base/path(/|$)(.*)
backend:
serviceName: myApi
servicePort: 8080
Run Code Online (Sandbox Code Playgroud)
但是,当我将 PUT 请求发送到 /base/path/v1/api/update 而不是获得 404 时,我获得了 500,这意味着可以从入口控制器访问该路径。有人可以帮我找出原因吗?
我改为配置片段,我得到的错误是:
Error: exit status 1
2020/08/06 18:35:07 [emerg] 1734#1734: location "/base/path/v1/api/update" is outside location "^/base/path(/|$)(.*)" in /tmp/nginx-cfg008325631:2445
nginx: [emerg] location "/base/path/v1/api/update" is outside location "^/base/path(/|$)(.*)" in /tmp/nginx-cfg008325631:2445
nginx: configuration file /tmp/nginx-cfg008325631 test failed
Run Code Online (Sandbox Code Playgroud)
添加我自己的答案:对我有用的最终配置是:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-configuration-snippet
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/server-snippet: |
location ~* "^/base/path/v1/api/update" {
deny all;
return 403;
}
spec:
rules:
- http:
paths:
- path: /base/path(/|$)(.*)
backend:
serviceName: myApi
servicePort: 8080
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2812 次 |
最近记录: |