From 176e5c7a9d220542f2e157a9435cb66576ba49ea Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Tue, 1 Jun 2021 12:29:33 +0200 Subject: [PATCH] fixed caching --- docker/nginx/conf.d/client.conf | 11 ++++++----- docker/nginx/conf.d/include/proxy-cache-downloads | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index b4dc0510..4212a813 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -436,6 +436,7 @@ server { # v2 support set $skylink_v1 $skylink; + set $skylink_v2 $skylink; access_by_lua_block { -- disable cache if this is skylink v2 @@ -443,7 +444,7 @@ server { local isBase64v2 = string.len(ngx.var.skylink) == 46 and string.sub(ngx.var.skylink, 0, 2) == "AQ" if isBase32v2 or isBase64v2 then - local res = ngx.location.capture("/skynet/resolve/" .. ngx.var.skylink) + local res = ngx.location.capture("/skynet/resolve/" .. ngx.var.skylink_v2) if res.status == ngx.HTTP_OK then local json = require('cjson') local resolve = json.decode(res.body) @@ -467,11 +468,11 @@ server { # in case siad returns location header and we have skylink v2, we need to replace the skylink v1 with v2 header_filter_by_lua_block { - if ngx.var.skylink ~= ngx.var.skylink_v1 then + if ngx.var.skylink_v1 ~= ngx.var.skylink_v2 then if ngx.header.location then - ngx.header.location = ngx.header.location:gsub("^" .. ngx.var.skylink_v1, ngx.var.skylink) + ngx.header.location = ngx.header.location:gsub("^" .. ngx.var.skylink_v1, ngx.var.skylink_v2) end - ngx.header["Skynet-Skylink"] = ngx.var.skylink + ngx.header["Skynet-Skylink"] = ngx.var.skylink_v2 end } @@ -498,7 +499,7 @@ server { proxy_read_timeout 600; proxy_set_header User-Agent: Sia-Agent; # proxy this call to siad /skynet/skylink/ endpoint (make sure the ip is correct) - proxy_pass http://siad/skynet/skylink/$skylink$path$is_args$args; + proxy_pass http://siad/skynet/skylink/$skylink_v1$path$is_args$args; } location @base32_subdomain { diff --git a/docker/nginx/conf.d/include/proxy-cache-downloads b/docker/nginx/conf.d/include/proxy-cache-downloads index a0dfa54f..35501503 100644 --- a/docker/nginx/conf.d/include/proxy-cache-downloads +++ b/docker/nginx/conf.d/include/proxy-cache-downloads @@ -3,7 +3,7 @@ proxy_cache skynet; # cache name slice 1m; proxy_http_version 1.1; # upgrade if necessary because 1.0 does not support byte-range requests proxy_set_header Range $slice_range; # pass slice range to proxy -proxy_cache_key $uri$arg_format$arg_attachment$slice_range; # use just the uri path, format and attachment args and slice range +proxy_cache_key $skylink_v1$path$arg_format$arg_attachment$slice_range; # use just the uri path, format and attachment args and slice range proxy_cache_min_uses 3; # cache responses after 3 requests of the same file proxy_cache_valid 200 206 24h; # cache 200 and 206 responses for 24 hours proxy_cache_lock on; # queue cache requests for the same resource until it is fully cached