fastcgi_cache_max_range_offset
Controls the maximum allowed offset for range requests in FastCGI caching.
Description
The fastcgi_cache_max_range_offset directive defines the maximum number of bytes that can be specified as an offset when a client makes a range request for a resource that is served from FastCGI caching. This directive helps to optimize the caching behavior and the response for partially downloaded resources, ensuring that the server does not over-serve outdated or excessive data when clients only request specific parts of a file.
Setting this directive with a numerical value allows you to control the granularity of the response to range requests for cached content. If the offset exceeds the specified value, NGINX may choose to reject the range request or treat it differently based on the implementation of the FastCGI module and the caching strategy in place. This can be particularly useful in scenarios where minimizing bandwidth usage is critical, or to deliver more efficient responses when dealing with large files that are frequently accessed in parts.
This directive can be applied in various contexts including the http, server, and location blocks within the NGINX configuration file, making it flexible for different usage scenarios and server configurations.
Config Example
http {
fastcgi_cache_path /var/cache/nginx/fastcgi_temp levels=1:2 keys_zone=my_cache:10m;
server {
location / {
fastcgi_pass backend;
fastcgi_cache my_cache;
fastcgi_cache_max_range_offset 1048576; # 1 MB
}
}
}Setting the offset too high can lead to unnecessary bandwidth usage for partial content retrieval.
If not set and a range request with a large offset occurs, it may cause NGINX to deny the request or respond with a 416 error.
Ensure that the size specified aligns with the expected range size of the content being served to avoid performance issues.