我需要允许来自多个来源的请求:http://localhost:4200,http://localhost:4242,等,nginx的上,入口版本1.7.1。但我无法为多个来源做到这一点,因为nginx.ingress.kubernetes.io/cors-allow-credentials: true不会与nginx.ingress.kubernetes.io/cors-allow-origin: "*". 它会导致浏览器生成 CORS 错误。也许有人有避免此错误的解决方案?
这是我的配置
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS, DELETE"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,X-LANG,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Api-Key,X-Device-Id,Access-Control-Allow-Origin"
Run Code Online (Sandbox Code Playgroud)
从源“ http://localhost:4200 ”访问“ https://stage.site.com/api/session ”的XMLHttpRequest已被 CORS 策略阻止:“Access-Control-Allow-Origin”的值当请求的凭据模式为“包含”时,响应中的标头不得为通配符“*”。XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。