ngx_http_slice_module
Split large proxied responses into cacheable byte-range slices
Overview
ngx_http_slice_module is a filter that splits a request into subrequests, each returning a certain byte range of the response. This provides more effective caching of big responses, because each slice is fetched and stored independently.
The module exposes $slice_range, the current slice in HTTP byte range format such as bytes=0-1048575. For a subrequest to return the right range that variable must be passed to the upstream as the Range header with proxy_set_header, and when caching is on it must also be part of proxy_cache_key and 206 responses must be made cacheable with proxy_cache_valid. Setting slice too low may cause excessive memory usage and a large number of open files.
It is an official nginx module, present since 1.9.8, and is not built by default upstream, so it needs the --with-http_slice_module configure parameter. Its typical use is a caching proxy in front of large downloads or video files where clients seek with range requests.
Key directives
sliceSets the size of each slice; default 0 disables splitting responses into slices.$slice_rangeThe current slice range in HTTP byte range format, for example bytes=0-1048575.proxy_set_header Range $slice_rangePasses the slice range to the proxied server so each subrequest returns only the needed bytes.proxy_cache_key with $slice_rangeAdds the slice range to the cache key so every slice is stored as a separate cache entry.proxy_cache_valid 200 206Makes the partial 206 responses returned for each slice cacheable alongside full 200 responses.Example
Availability
Compiled into every n.wtf nginx binary. Install nginx-extras and the directives above work out of the box, no load_module line needed.