Configuring Caching on Nginx

published onJanuary 27, 2017
0views
3minutes read
To optimize the server for faster access, sysadmins typically add caching settings to their servers. Usually, Nginx is combined with Varnish, which acts as a proxy caching solution. However, personally, I find that setting up Nginx caching alone is sufficient, considering Nginx also supports acting as a caching server similar to Varnish. Perhaps we'll discuss the combination of Nginx and Varnish, as well as Nginx installation on Ubuntu, another time.
Configuring it is straightforward. Edit your Nginx server block, or if you're not using a server block, edit its default configuration.
Then, add the following configuration before the closing curly brace (
) at the end.
Here, I've set caching for RSS files for one hour, media files like images and videos for one month (30 days), and CSS and JS files for one year.
The
is set to
to allow caching by all devices.
Then, restart the Nginx service.
Tags:
#Nginx
#SysAdmin
#Web Server