proxy_store

The `proxy_store` directive allows the storage of proxied responses in the local file system. — NGINX HTTP Core

proxy_store
httpserverlocation
Синтаксисproxy_store on | off;
По умолчаниюoff
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы1

Описание

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.

Пример конфига

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.