fixed caching
This commit is contained in:
parent
a2a4b6ea8f
commit
176e5c7a9d
|
@ -436,6 +436,7 @@ server {
|
||||||
|
|
||||||
# v2 support
|
# v2 support
|
||||||
set $skylink_v1 $skylink;
|
set $skylink_v1 $skylink;
|
||||||
|
set $skylink_v2 $skylink;
|
||||||
|
|
||||||
access_by_lua_block {
|
access_by_lua_block {
|
||||||
-- disable cache if this is skylink v2
|
-- 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"
|
local isBase64v2 = string.len(ngx.var.skylink) == 46 and string.sub(ngx.var.skylink, 0, 2) == "AQ"
|
||||||
|
|
||||||
if isBase32v2 or isBase64v2 then
|
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
|
if res.status == ngx.HTTP_OK then
|
||||||
local json = require('cjson')
|
local json = require('cjson')
|
||||||
local resolve = json.decode(res.body)
|
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
|
# 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 {
|
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
|
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
|
end
|
||||||
ngx.header["Skynet-Skylink"] = ngx.var.skylink
|
ngx.header["Skynet-Skylink"] = ngx.var.skylink_v2
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +499,7 @@ server {
|
||||||
proxy_read_timeout 600;
|
proxy_read_timeout 600;
|
||||||
proxy_set_header User-Agent: Sia-Agent;
|
proxy_set_header User-Agent: Sia-Agent;
|
||||||
# proxy this call to siad /skynet/skylink/ endpoint (make sure the ip is correct)
|
# 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 {
|
location @base32_subdomain {
|
||||||
|
|
|
@ -3,7 +3,7 @@ proxy_cache skynet; # cache name
|
||||||
slice 1m;
|
slice 1m;
|
||||||
proxy_http_version 1.1; # upgrade if necessary because 1.0 does not support byte-range requests
|
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_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_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_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
|
proxy_cache_lock on; # queue cache requests for the same resource until it is fully cached
|
||||||
|
|
Reference in New Issue