Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes nginx ingress controller / caching static assets

I have a problem about the images returned via the apps running behind the nginx ingress controller. They always returns 200 instead of an expected 304 once visited.

Digging around, i've found out about the ability to add specific blocks within the servers; so added the following under metadata > annotations :

 ingress.kubernetes.io/server-snippets: |
   location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
     expires 30d;
     add_header Pragma public;
     add_header Cache-Control "public";
   }

The problems persists, so still getting a permanent 200; "ssh'ing" into the nginx pod and doing a cat on the nginx.conf created, I don't see this block appearing anywhere

So am kind of lost about how to improve it. I'm using kube-lego, but did not found out if it could have an impact here

like image 247
Ben Avatar asked Oct 24 '25 08:10

Ben


2 Answers

In case somebody else stumbles upon this (probably be me in the future), the annotation is nginx.ingress.kubernetes.io/server-snippet.

like image 142
AWippler Avatar answered Oct 27 '25 00:10

AWippler


Support for server-snippets annotation was added in nginx-0.9.0-beta.16. Upgrade your ingress controller image to quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0-beta.16

like image 32
Droga Mleczna Avatar answered Oct 27 '25 02:10

Droga Mleczna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!