parent
fc24b64479
commit
b7d9c35c8a
|
@ -9,14 +9,6 @@ limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
|
||||||
# this is important because we want only one format in cache keys and logs
|
# 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) }
|
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
|
# variable for Skynet-Proof header that we need to inject
|
||||||
# into a response if the request was for skylink v2
|
# into a response if the request was for skylink v2
|
||||||
set $skynet_proof '';
|
set $skynet_proof '';
|
||||||
|
@ -53,5 +45,4 @@ 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
|
# 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
|
# 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
|
# 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$path$is_args$args;
|
||||||
proxy_pass http://sia:9980/skynet/skylink/$skylink_v1$path$is_args$args;
|
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
add_header X-Proxy-Cache $upstream_cache_status; # add response header to indicate cache hits and misses
|
add_header X-Proxy-Cache $upstream_cache_status; # add response header to indicate cache hits and misses
|
||||||
|
|
||||||
# bypass - this will bypass cache hit on request (status BYPASS)
|
# disable caching
|
||||||
# but still stores file in cache if cache conditions are met
|
proxy_no_cache "1";
|
||||||
proxy_cache_bypass $cookie_nocache $arg_nocache "1";
|
|
||||||
|
|
||||||
# no cache - this will ignore cache on request (status MISS)
|
|
||||||
# and does not store file in cache under no condition
|
|
||||||
set $nocache "1";
|
|
||||||
|
|
||||||
# disable cache when nocache is set or skyd cache is enabled
|
|
||||||
proxy_no_cache $nocache;
|
|
||||||
|
|
|
@ -14,9 +14,6 @@ local anon_limits = {
|
||||||
["registry"] = 250
|
["registry"] = 250
|
||||||
}
|
}
|
||||||
|
|
||||||
-- basic caching of user data
|
|
||||||
local curr_limits
|
|
||||||
|
|
||||||
-- handle request exit when access to portal should be restricted to authenticated users only
|
-- handle request exit when access to portal should be restricted to authenticated users only
|
||||||
function _M.exit_access_unauthorized(message)
|
function _M.exit_access_unauthorized(message)
|
||||||
ngx.status = ngx.HTTP_UNAUTHORIZED
|
ngx.status = ngx.HTTP_UNAUTHORIZED
|
||||||
|
@ -38,10 +35,6 @@ function _M.accounts_enabled()
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.get_account_limits()
|
function _M.get_account_limits()
|
||||||
if curr_limits ~= nil then
|
|
||||||
return curr_limits
|
|
||||||
end
|
|
||||||
|
|
||||||
local cjson = require('cjson')
|
local cjson = require('cjson')
|
||||||
|
|
||||||
-- TODO: This needs to accommodate authorization tokens and api keys.
|
-- TODO: This needs to accommodate authorization tokens and api keys.
|
||||||
|
@ -66,8 +59,7 @@ function _M.get_account_limits()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
curr_limits = cjson.decode(ngx.var.account_limits)
|
return cjson.decode(ngx.var.account_limits)
|
||||||
return curr_limits
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- detect whether current user is authenticated
|
-- detect whether current user is authenticated
|
||||||
|
|
Reference in New Issue