Second attempt at conditionally slicing requests

This commit is contained in:
Goten Xiao 2024-09-01 13:11:56 +01:00
parent 1bbb96230c
commit 187e0fe66b
5 changed files with 27 additions and 6 deletions

View file

@ -1,4 +1,15 @@
map "${cacheidentifier}${http_range}" $slice_range_actual { map "${cacheidentifier}${http_range}" $lcn_use_slicing {
default 1; # Use the calculated slice range by default
~steam$ 0; # Disable slicing for Steam when the client request isn't a range, as not all CDN nodes accept range requests
}
# map of location names to use for sliced/unsliced requests
map "${lcn_use_slicing}" $lcn_request_location_name {
1 "@lcn_sliced_request";
0 "@lcn_unsliced_request";
}
map "${cacheidentifier}${http_range}" $lcn_slice_range {
default $slice_range; # Use the calculated slice range by default default $slice_range; # Use the calculated slice range by default
~steam$ ""; # Disable slicing for Steam when the client request isn't a range, as not all CDN nodes accept range requests ~steam$ ""; # Disable slicing for Steam when the client request isn't a range, as not all CDN nodes accept range requests
} }

View file

@ -1,7 +1,20 @@
resolver UPSTREAM_DNS ipv6=off; resolver UPSTREAM_DNS ipv6=off;
location / { location / {
# use the location block named by $lcn_request_location_name - set in 31_slice_maps.conf - to service the request
try_files "" $lcn_request_location_name;
}
location @lcn_sliced_request {
slice 1m;
include /etc/nginx/sites-available/cache.conf.d/root/*.conf; include /etc/nginx/sites-available/cache.conf.d/root/*.conf;
# $lcn_slice_range is set from the map in 31_slice_maps.conf
proxy_set_header Range $lcn_slice_range;
}
location @lcn_unsliced_request {
# slice directive deliberately not included
include /etc/nginx/sites-available/cache.conf.d/root/*.conf;
} }

View file

@ -1,11 +1,8 @@
# Cache Location # Cache Location
slice 1m;
proxy_cache generic; proxy_cache generic;
proxy_ignore_headers Expires Cache-Control; proxy_ignore_headers Expires Cache-Control;
proxy_cache_valid 200 206 CACHE_MAX_AGE; proxy_cache_valid 200 206 CACHE_MAX_AGE;
# $slice_range_actual is set from the map in 31_slice_maps.conf
proxy_set_header Range $slice_range_actual;
# Only download one copy at a time and use a large timeout so # Only download one copy at a time and use a large timeout so
# this really happens, otherwise we end up wasting bandwith # this really happens, otherwise we end up wasting bandwith

View file

@ -1 +1 @@
proxy_cache_key $cacheidentifier$uri$slice_range_actual; proxy_cache_key $cacheidentifier$uri$lcn_slice_range;

View file

@ -16,7 +16,7 @@ sed -i "s/CACHE_DISK_SIZE/${CACHE_DISK_SIZE}/" /etc/nginx/conf.d/20_proxy_cache_
sed -i "s/MIN_FREE_DISK/${MIN_FREE_DISK}/" /etc/nginx/conf.d/20_proxy_cache_path.conf sed -i "s/MIN_FREE_DISK/${MIN_FREE_DISK}/" /etc/nginx/conf.d/20_proxy_cache_path.conf
sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/conf.d/20_proxy_cache_path.conf sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/conf.d/20_proxy_cache_path.conf
sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf
sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cache.conf.d/10_root.conf
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf