Nginx – How to set expires headers for images

Categories: nginx
In Nginx, you can easily set browser caching for your images. Nginx sets the ‘Expires’ and ‘Cache-Control’ http request headers for images nginx serves. This allows the client’s browser to cache the images for the amount of time specified by the expires tag inside the location block of code. Here’s the location block I’m using in my Nginx virtual host configuration file: location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires 1y; log_not_found off; } You can use the curl command on unix/linux/mac to see the full headers for a request.

Read More →