fastcgi_store
The fastcgi_store directive enables storing of FastCGI responses to a specified location on the disk.
Description
The fastcgi_store directive is used to define the behavior of NGINX in relation to storing the response received from a FastCGI server. When this directive is set, it instructs NGINX to save the response body of the FastCGI application to a file on the disk, allowing for improved efficiency of serving repeated requests for the same FastCGI resource.
When specified, the first argument should be a valid file path or URI where the response should be stored. This supports various file system capabilities; for instance, it can be a dynamically generated file path based on request variables or a static path. The mode of storage can also involve the setting of file permissions based on the configuration that one may want — very useful when setting up file permissions for serving static files from FastCGI responses.
Additionally, the directive has implications on caching as it allows a more persistent caching mechanism compared to standard in-memory caching since it stores the responses as files. However, careful consideration is needed in configuring the storage path, permissions, and cleanup strategies for these stored files to manage disk space appropriately during operation.
Config Example
location /example {
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_store on;
fastcgi_store_access user:rw group:rw all:r;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}Ensure that the path specified for storage is writable by the NGINX process; otherwise, responses will not be stored correctly.
Be cautious with disk space; as files accumulate, monitoring and cleanup strategies may be required to prevent disk overuse.
Using dynamic paths for storage without the right variable formatting can lead to unexpected behavior.