Kubernetes Ingress-nginx跨域配置

Kubernetes网关ingress-nginx配置新增跨域配置,解决前端页面无法访问!!!

nginx.ingress.kubernetes.io/Access-Control-Allow-Origin: '*'
nginx.ingress.kubernetes.io/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization
nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
nginx.ingress.kubernetes.io/cors-allow-origin: '*'

示例如下:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: gc-xxxxx-com
  namespace: gc-prod
  annotations:
    nginx.ingress.kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-body-size: "200m" # 上传包大小控制
    nginx.ingress.kubernetes.io/use-regex: "true"  #支持正则表达
    nginx.ingress.kubernetes.io/permanent-redirect-code: '301' #修改默认永久重定向状态码308为301
    nginx.ingress.kubernetes.io/secure-backends: "true" #这里有可能我安装的是旧版ingress-nginx(backend-protocol是同一个协议)
    #nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" #NGINX应如何与后端服务通信(默认是http)
    #nginx.ingress.kubernetes.io/ssl-passthrough: "true" #控制器将TLS连接直接发送到后端,而不是让NGINX解密通信
    #nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    #nginx.ingress.kubernetes.io/ssl-redirect: "true"   # http强制跳转https
    nginx.ingress.kubernetes.io/Access-Control-Allow-Origin: '*'
    nginx.ingress.kubernetes.io/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization
    nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
    nginx.ingress.kubernetes.io/cors-allow-origin: '*'
spec:
  tls:
  - hosts:
    - gc-alpha.xxxxxx.com
    secretName: tls-gcore-com
  rules:
  - host: gc-alpha.xxxxxx.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: alpha-gc-web
            port:
              number: 80

你可能感兴趣的:(kubernetes,nginx,容器)