nginx: Expires for pictures

After I first tried to persuade nginx to only provide images with an expires header via a corresponding "location" block. Unfortunately, this did not work (result: images were no longer found). Solution: for the global location set accordingly grab the expires header (now set to 8d for me).

location / {
root /var/www;
try_files $uri $uri/ /index.php;
expires 8d;
}

At least in my case, this applies to images and other static files, especially images. Dynamic files like PHP scripts are not affected by this. Overall, this blog is now on a page speed score of 82/100, which is also helped by enabled browser caching. Next plan: ban JavaScript to the end of the page and combine images in sprites (to further reduce the number of requests).

Leave a Comment

Your email address will not be published.

en_USEnglish
Scroll to Top