Complete the code to enable FastCGI cache in nginx configuration.
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m [1] inactive=60m;
The max_size directive sets the maximum size of the cache. 100m is a common safe default.
Complete the code to set the cache key for FastCGI cache.
fastcgi_cache_key [1];The cache key should uniquely identify the request. Using scheme, method, host, and URI is common.
Fix the error in the FastCGI cache configuration to enable caching in the location block.
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_cache [1];
include fastcgi_params;
}The fastcgi_cache directive must reference the name of the cache zone defined by keys_zone, here my_cache.
Fill both blanks to set cache validity times for different response codes.
fastcgi_cache_valid 200 [1]; fastcgi_cache_valid 404 [2];
Successful responses (200) are cached longer (10 minutes), while 404 errors are cached shorter (1 minute).
Fill all three blanks to configure cache bypass and cache use conditions.
fastcgi_cache_bypass [1]; fastcgi_no_cache [2]; fastcgi_cache_use_stale [3];
fastcgi_cache_bypass disables cache if $cookie_nocache is set.fastcgi_no_cache disables cache if $http_cache_control header is present.fastcgi_cache_use_stale allows serving stale cache on errors like 500 or timeout.