nginx入口为特定路径添加自定义头

nginx入口为特定路径添加自定义头,nginx,nginx-ingress,Nginx,Nginx Ingress,我在kubernetes环境中有以下nginx入口 apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/configuration-snippet: | more_set_headers "cache-control: no-store"; mo

我在kubernetes环境中有以下nginx入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "cache-control: no-store";
      more_set_headers "MyCustomHeader: Value";
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: svc1
          servicePort: 80
          # Want to add the custom headers in this path only
        path: /
      - backend:
          serviceName: svc2
          servicePort: 80
        path: /cacheable-path
我有两个要设置的头
缓存控制
MyCustomHeader
。但我希望仅为根路径
/
设置这些头,而不为其他路由(如
/cacheable path
)设置这些头


如何做到这一点?添加注释会将标题附加到所有响应中。我只希望将头添加到特定路径。

无法在单个入口资源中为特定路径添加头。您必须创建两个入口资源

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "cache-control: no-store";
      more_set_headers "MyCustomHeader: Value";
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: svc1
          servicePort: 80
        path: /
不带标题

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: svc2
          servicePort: 80
        path: /cacheable-path