Reverse Proxy Advanced Topics
[ 110 ]
The following configuration summarizes the directives used to store these files:
http {
proxy_temp_path /var/www/tmp;
server {
root /var/www/data
location /img {
error_page 404 = @store;
}
location @store {
internal;
proxy_store on;
proxy_store_access group:r all:r;
proxy_pass http://upstream;
}
}
}
In this configuration, we define a server with a root under the same filesystem as
the proxy_temp_path. The location directive /img will inherit this root, serving
files of the same name as the URI path under /var/www/data. If a file is not found
(error code 404), the named location directive @store is called to fetch the file from
the upstream. The proxy_store directive indicates that we want to store files under
the inherited root with permissions 0644 (the user:rw is understood, while group
or all are specified in proxy_store_access). That's all it takes for NGINX to store
a local copy of static files served by the upstream server.