diff --git a/overlay/etc/nginx/conf.d/31_slice_maps.conf b/overlay/etc/nginx/conf.d/31_slice_maps.conf index 3025356..c5b24c6 100644 --- a/overlay/etc/nginx/conf.d/31_slice_maps.conf +++ b/overlay/etc/nginx/conf.d/31_slice_maps.conf @@ -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 ~steam$ ""; # Disable slicing for Steam when the client request isn't a range, as not all CDN nodes accept range requests } diff --git a/overlay/etc/nginx/sites-available/cache.conf.d/10_root.conf b/overlay/etc/nginx/sites-available/cache.conf.d/10_root.conf index f065502..27b55d4 100644 --- a/overlay/etc/nginx/sites-available/cache.conf.d/10_root.conf +++ b/overlay/etc/nginx/sites-available/cache.conf.d/10_root.conf @@ -1,7 +1,20 @@ resolver UPSTREAM_DNS ipv6=off; 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; + # $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; } diff --git a/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf b/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf index e016760..4b519cf 100644 --- a/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf +++ b/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf @@ -1,11 +1,8 @@ # Cache Location - slice 1m; proxy_cache generic; proxy_ignore_headers Expires Cache-Control; 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 # this really happens, otherwise we end up wasting bandwith diff --git a/overlay/etc/nginx/sites-available/cache.conf.d/root/30_cache_key.conf b/overlay/etc/nginx/sites-available/cache.conf.d/root/30_cache_key.conf index c406a4b..60d88c6 100644 --- a/overlay/etc/nginx/sites-available/cache.conf.d/root/30_cache_key.conf +++ b/overlay/etc/nginx/sites-available/cache.conf.d/root/30_cache_key.conf @@ -1 +1 @@ - proxy_cache_key $cacheidentifier$uri$slice_range_actual; + proxy_cache_key $cacheidentifier$uri$lcn_slice_range; diff --git a/overlay/hooks/entrypoint-pre.d/10_setup.sh b/overlay/hooks/entrypoint-pre.d/10_setup.sh index 039f645..b1cf284 100644 --- a/overlay/hooks/entrypoint-pre.d/10_setup.sh +++ b/overlay/hooks/entrypoint-pre.d/10_setup.sh @@ -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/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/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/upstream.conf.d/10_resolver.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf