Nginx ingress 配置 CORS 跨域资源共享

如果我们的Api跟主站不是用同一个域名的话。我们就得给API配置跨域资源共享 (这个东西做在api里面也是很容易的。)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-redirection-live
  namespace: malema-live
  annotations:
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, DELETE, PATCH, OPTIONS" # separated by ',' 
    nginx.ingress.kubernetes.io/cors-allow-origin: "https://origin-site.com:4443, http://origin-site.com, https://example.org:1199" 
    nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
    nginx.ingress.kubernetes.io/cors-max-age: 600

cors-allow-origin 还支持一个通配符 如下

http(s)://*.foo.bar, http(s)://*.bar.foo:8080 or http(s)://*.abc.bar.foo:9000

Example:

nginx.ingress.kubernetes.io/cors-allow-origin: "https://*.origin-site.com:4443, http://*.origin-site.com, https://example.org:1199"
最近更新的
...