Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aem99's avatar
Level 3

Nginx static files browser caching

Hi,

This not necessary a Laravel question, but all of my static files (img|js|css) and so on, are only caching for 4 hours. I tried to increase that but with no luck. I added this block to nginx config:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 365d;
}

and reload the nginx. My image path is /public/images/***.png, so the regex should capture it. However, that's not happening, when I curl to get the image the max-age is set to 14400 which is still 4 hours. Not sure what is happening there.

My Nginx config

0 likes
2 replies
matth's avatar

I just tested that config and it works fine for setting the expiration.

Are you maybe routing your site through something like CloudFlare which could either be caching the expires header from before you set it or setting its own expires headers in the settings?

1 like
sNok3's avatar

@matth Your reply helped me a year later after googling for 2 hours and trying different configs. Thanks a lot!

1 like

Please or to participate in this conversation.