Once Nginx is set up as a reverse proxy, it's logical to turn it into a caching proxy. Fortunately, this can be achieved very easily with Nginx.
Before you can enable caching for a certain location, you need to configure a cache. A cache is a filesystem directory containing files with cached items and a shared memory segment where information about cached items is stored.
A cache can be declared using the proxy_cache_path
directive:
proxy_cache_path <path> keys_zone=<name>:<size> [other parameters...];
The preceding command declares a cache rooted at the path <path>
with a shared memory segment named <name>
of the size <size>
.
This directive has to be specified in the http
section of the configuration. Each instance of the directive declares a new cache and must specify a unique name for a shared memory segment. Consider the following example:
http { proxy_cache_path /var/www/cache keys_zone=my_cache:8m; [...] }
The preceding...