proxy_store

The `proxy_store` directive allows the storage of proxied responses in the local file system.

Syntaxproxy_store on | off;
Defaultoff
Contexthttp, server, location
Arguments1

Description

The proxy_store directive is utilized within the context of http, server, or location blocks to enable storing the responses from proxied servers into the local filesystem. When set to on, NGINX will save the response of a proxied request, based on the configured URI, to a specified local file or directory.

The directive requires an argument that specifies the directory path where the files will be stored. If the directory does not exist, NGINX will not create it, and a 404 error will occur when a request is made. This makes it essential to have proper permissions to write to the designated directory. Additionally, the directive can be combined with other settings, like proxy_pass, to allow routing to a backend service while simultaneously preserving the response in a file for later retrieval.

When using proxy_store, it's also essential to consider the implications of directory structure management and response caching. Responses will be stored in a flat structure unless an appropriate hashing or custom URI handling configuration is applied. Therefore, care should be taken in how URIs are structured to prevent file overwrites and ensure clear access patterns.

Config Example

location /downloads {
    proxy_pass http://backend;
    proxy_store on;
    proxy_store_path /var/www/stored_files;
}

Ensure the specified path for storage exists and has the correct permissions.

If multiple requests map to the same URI, responses will overwrite each other unless handled properly.

Remember that proxy_store does not handle dynamic data well since it stores the response based on the URI directly.

← Back to all directives