voi*_*urn 2 nginx 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/configuration-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)
但是当我向 https:///base/path/v1/api/update 发送请求时,它成功了,并且在 nginx 入口控制器中出现了以下错误
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)
有人可以帮忙吗?
在配置-摘录是添加CONFIGS到位置。
如果要将自定义位置添加到服务器上下文,则应使用server-snippet:
使用注释
nginx.ingress.kubernetes.io/server-snippet可以在服务器配置块中添加自定义配置。
您还需要使用一些修饰符和正则表达式来使其工作(~*和^)。
以下配置应该可以工作:
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)
决赛nginx.config应该是这样结束的:
$ kubectl exec -n kube-system nginx-ingress-controller-6fc5bcc8c9-chkxf -- cat /etc/nginx/nginx.conf
[...]
location ~* "^/base/path/v1/api/update" {
deny all;
return 403;
}
location ~* "^/base/path(/|$)(.*)" {
[...]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4653 次 |
| 最近记录: |