From 197c05fef28bd8d5bbadf03101f98279b9ae561c Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Mon, 14 Mar 2022 12:22:18 +0100 Subject: [PATCH] skylinkv1 --- docker/nginx/conf.d/include/location-skylink | 16 ---------------- .../nginx/conf.d/include/proxy-cache-downloads | 3 +-- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/docker/nginx/conf.d/include/location-skylink b/docker/nginx/conf.d/include/location-skylink index c47bb2f8..8e52b996 100644 --- a/docker/nginx/conf.d/include/location-skylink +++ b/docker/nginx/conf.d/include/location-skylink @@ -3,20 +3,10 @@ include /etc/nginx/conf.d/include/proxy-buffer; include /etc/nginx/conf.d/include/proxy-cache-downloads; include /etc/nginx/conf.d/include/track-download; -limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time - # ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones) # this is important because we want only one format in cache keys and logs set_by_lua_block $skylink { return require("skynet.skylink").parse(ngx.var.skylink) } -# $skylink_v1 and $skylink_v2 variables default to the same value but in case the requested skylink was: -# a) skylink v1 - it would not matter, no additional logic is executed -# b) skylink v2 - in a lua block below we will resolve the skylink v2 into skylink v1 and update -# $skylink_v1 variable so then the proxy request to skyd can be cached in nginx (proxy_cache_key -# in proxy-cache-downloads includes $skylink_v1 as a part of the cache key) -set $skylink_v1 $skylink; -set $skylink_v2 $skylink; - # variable for Skynet-Proof header that we need to inject # into a response if the request was for skylink v2 set $skynet_proof ''; @@ -102,9 +92,3 @@ header_filter_by_lua_block { proxy_read_timeout 600; proxy_set_header User-Agent: Sia-Agent; - -# in case the requested skylink was v2 and we already resolved it to skylink v1, we are going to pass resolved -# skylink v1 to skyd to save that extra skylink v2 lookup in skyd but in turn, in case skyd returns a redirect -# we need to rewrite the skylink v1 to skylink v2 in the location header with proxy_redirect -proxy_redirect $skylink_v1 $skylink_v2; -proxy_pass http://sia:9980/skynet/skylink/$skylink_v1$path$is_args$args; diff --git a/docker/nginx/conf.d/include/proxy-cache-downloads b/docker/nginx/conf.d/include/proxy-cache-downloads index 8a36f6cd..94a635e1 100644 --- a/docker/nginx/conf.d/include/proxy-cache-downloads +++ b/docker/nginx/conf.d/include/proxy-cache-downloads @@ -1,6 +1,5 @@ proxy_cache skynet; # cache name -proxy_cache_key $skylink_v1$path$arg_format$arg_attachment$arg_start$arg_end$http_range; # unique cache key -#proxy_cache_key $skylink$path$arg_format$arg_attachment$arg_start$arg_end$http_range; # unique cache key +proxy_cache_key $skylink$path$arg_format$arg_attachment$arg_start$arg_end$http_range; # unique cache key proxy_cache_min_uses 3; # cache after 3 uses proxy_cache_valid 200 206 307 308 48h; # keep 200, 206, 307 and 308 responses valid for up to 2 days add_header X-Proxy-Cache $upstream_cache_status; # add response header to indicate cache hits and misses