fastcgi_cache_path

Specifies the path for storing cached data when using FastCGI caching.

Syntaxfastcgi_cache_path path [levels=levels] [zone=name:size] [inactive=time] [max_size=size];
Defaultnone
Contexthttp
Arguments2+

Description

The fastcgi_cache_path directive is used to define the storage configuration for FastCGI cache in NGINX. This directive is specified within the http block and establishes the path where cached files will be stored, along with settings for cache zone size, keys, and other parameters. It essentially creates a directory that holds response data coming from the FastCGI server, which can significantly speed up the response time by serving cached content instead of forwarding requests to the backend server each time.

This directive requires a minimum of two arguments: the cache path and the cache zone configuration string, which typically includes a name and size for the cache. The cache zone is where NGINX identifies how to segment and manage cached responses. Additional parameters such as inactive or max_size can also be included to specify how long items will stay in cache or the maximum size of the cache respectively. The importance of this directive cannot be understated, as properly configuring the FastCGI cache can lead to improved performance and reduced load on backend servers.

Config Example

http {
    fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2 keys_zone=fastcgi_cache:10m inactive=60m max_size=1g;
}

Ensure the specified path has appropriate permissions for NGINX to write cache files.

If cache size exceeds the specified max_size, NGINX will start removing the least recently used cache files, which can impact performance if not configured properly.

← Back to all directives