gpt4 book ai didi

kubernetes nginx ingress server-snippet 注释没有生效

转载 作者:行者123 更新时间:2023-12-02 12:00:16 31 4
gpt4 key购买 nike

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

但是当我将 PUT 请求发送到/base/path/v1/api/update 而不是得到 404 时,我得到的是 500,这意味着路径可以从入口 Controller 到达。谁能帮我找出原因?

我更改为配置片段,得到的错误是:

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

最佳答案

添加我自己的答案:对我有用的最终配置是:

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

关于kubernetes nginx ingress server-snippet 注释没有生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63275239/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com