gpt4 book ai didi

dictionary - map 指令未正确读取 nginx 入口 Controller kubernetes

转载 作者:行者123 更新时间:2023-12-02 12:34:15 24 4
gpt4 key购买 nike

这是 ConfigMap 资源:

kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-configuration
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
data:
use-proxy-protocol: "false"
use-forwarded-headers: "true"
proxy-real-ip-cidr: "0.0.0.0/0" # restrict this to the IP addresses of ELB
http-snippet: "map $http_origin $cors {
hostnames;

default 'default.com';
.local $http_origin;
.blah.org $http_origin;
}"

然后我得到了以下 Ingress 资源,它正在读取我之前在 ConfigMap nginx.ingress.kubernetes.io/cors-allow-origin: "$cors" 上设置的 map 指令的值:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
namespace: "default"
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "$cors"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, HEAD, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-headers: "Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With"
.
.
.

我遇到的问题是注释没有正确读取 map 指令上设置的 $cors 变量,并且生成的 nginx.conf 文件总是将“add_header 'Access-Control-Allow-Origin' 响应头设置为“* ”。

我在这里错过了什么吗?

最佳答案

这是 nginx.ingress.kubernetes.io/cors-allow-origin 中 CORS 实现的众所周知的行为。注释,仅限于单个值(硬编码格式)或 * ,查看 Nginx Ingress Controller documentation :

nginx.ingress.kubernetes.io/cors-allow-origin controls what's the accepted Origin for CORS. This is a single field value, with the following format: http(s)://origin-site.com or http(s)://origin-site.com:port



因此,为了在 origin header 中支持多个域,我假设您可能会考虑注入(inject)一些可以完成工作的脚本。有专门的FR提出 #1171 ,使用@claudiuchis 提供的片段来完成它。

关于dictionary - map 指令未正确读取 nginx 入口 Controller kubernetes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56941847/

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