Disable cache control in nginx ingress controler for certain response

让人想犯罪 __ 提交于 2021-02-11 12:32:00

问题


I have this ingress configuration but all html and json reponse pages dont contain the added header:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ $app }}-ingress
  labels:
    app: {{ $app }} 
    chart: chart-{{ $app }}
    app.kubernetes.io/managed-by: Helm
  annotations:
    meta.helm.sh/release-name: {{ $app }}
    meta.helm.sh/release-namespace: {{ .Release.Namespace }}
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "{{ $proxy_body_size }}"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "{{ $proxy_read_timeout }}"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "{{ $proxy_connect_timeout }}"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "{{ $proxy_send_timeout }}"
    nginx.ingress.kubernetes.io/proxy-buffer-size: "{{ $proxy_buffer_size }}"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/configuration-snippet : |
        if ($request_uri ~* \.(html|json)) {
           add_header Cache-Control "no-cache,no-store";
        }
spec:
  tls:
    - hosts:
        - {{ $alias }}
  rules:
    - host: {{ $alias }}
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: {{ $app }}-service
              servicePort: http-back

I want to disable cache control only for html and json content response. When I remove the if ($request_uri ~* .(html|json)) condition, all responses have the added header. So this means that the condition in the configuration-snippet is not correct.

Can you help please?

来源:https://stackoverflow.com/questions/65907441/disable-cache-control-in-nginx-ingress-controler-for-certain-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!