title: Setting cache-control headers for nginx ingress controller on kubernetes GKE
body: <p>I have an ingress-nginx controller handling traffic to my Kubernetes cluster hosted on GKE. I set it up using helm installation instructions from docs:</p>
  
  <p><a href="https://kubernetes.github.io/ingress-nginx/" rel="noreferrer">Docs here</a></p>
  
  <p>For the most part everything is working, but if I try to set cache related parameters via a <code>server-snippet</code> annotation, all of the served content that should get the cache-control headers comes back as a <code>404</code>.</p>
  
  <p>Here's my <code>ingress-service.yaml</code> file:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: ingress-service
    annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/proxy-read-timeout: "4000"
      nginx.ingress.kubernetes.io/proxy-send-timeout: "4000"
      nginx.ingress.kubernetes.io/server-snippet: |
        location ~* \.(js|css|gif|jpe?g|png)$ {
          expires 1M;
          add_header Cache-Control "public";
        }
  spec:
    tls:
      - hosts:
          - example.com
        secretName: example-com
    rules:
      - host: example.com
        http:
         paths:
          - path: /
            backend:
              serviceName: client-cluster-ip-service
              servicePort: 5000
          - path: /api/
            backend:
              serviceName: server-cluster-ip-service
              servicePort: 4000
  </code></pre>
  
  <p>Again, it's only the resources that are matched by the regex that come back as <code>404</code> (all <code>.js</code> files, <code>.css</code> files, etc.).</p>
  
  <p>Any thoughts on why this would be happening?</p>
  
  <p>Any help is appreciated!</p>