配置片段出现kubernetes nginx入口错误



我有以下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

但是当我向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

有人能帮忙吗?

配置片段是将configs添加到位置

如果你想在服务器上下文中添加一个自定义位置,你应该使用服务器代码段:

使用注释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

最后的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(/|$)(.*)" {
[...]           
}

相关内容

  • 没有找到相关文章

最新更新