Cache control using a map in Nginx
Google’s delightful Lighthouse utility moaned at me about cache-control. For that particular site I use Nginx as a reverse proxy to NodeJS.
Nginx allows us to set a map for filetypes and apply that map to one or more server definitions. To define the map create the following near the top of your configuration file:
In the above example,
epoch sets the expiry time of all html to 1st January 1970 (which we all know was a Thursday).
max on the other hand sets the expiry time to 31st December 2037 (a Friday). Other options
off or a specific time.
The last entry,
~image will apply to rule to any content type beginning with
image/, for example
To apply the map add the following line inside the server block: