Mastering Nginx

(Ron) #1
Chapter 7

[ 161 ]


  • Any image will be cached for as long as possible, due to the images
    also being stored in the database, making it a truly expensive operation
    to retrieve them


We will configure NGINX to support this strategy as follows:


http {

# here we configure two separate shared memory zones for the keys/
metadata
# and filesystem paths for the cached objects themselves
proxy_cache_path /var/spool/nginx/articles keys_zone=ARTICLES:16m
levels=1:2 inactive=1d;

proxy_cache_path /var/spool/nginx/images keys_zone=IMAGES:128m
levels=1:2 inactive=30d;

# but both paths still lie on the same filesystem as proxy_temp_
path
proxy_temp_path /var/spool/nginx;

server {

location / {

# this is where the list of articles is found
proxy_cache_valid 1m;

}

location /articles {

# each article has a URI beginning with "/articles"
proxy_cache_valid 1d;

}

location /img {

# every image is referenced with a URI under "/img"
proxy_cache_valid 10y;

}

}

That takes care of our requirements. We have now activated caching for a legacy
application that has no caching support.

Free download pdf