disable nginx cache download
This commit is contained in:
parent
f5ac3da694
commit
9b95c671ac
|
@ -1,6 +1,6 @@
|
||||||
include /etc/nginx/conf.d/include/cors;
|
include /etc/nginx/conf.d/include/cors;
|
||||||
include /etc/nginx/conf.d/include/proxy-buffer;
|
include /etc/nginx/conf.d/include/proxy-buffer;
|
||||||
include /etc/nginx/conf.d/include/proxy-cache-downloads;
|
#include /etc/nginx/conf.d/include/proxy-cache-downloads;
|
||||||
include /etc/nginx/conf.d/include/track-download;
|
include /etc/nginx/conf.d/include/track-download;
|
||||||
|
|
||||||
# ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones)
|
# ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones)
|
||||||
|
@ -12,45 +12,45 @@ set_by_lua_block $skylink { return require("skynet.skylink").parse(ngx.var.skyli
|
||||||
set $skynet_proof '';
|
set $skynet_proof '';
|
||||||
|
|
||||||
access_by_lua_block {
|
access_by_lua_block {
|
||||||
-- the block below only makes sense if we are using nginx cache
|
# -- the block below only makes sense if we are using nginx cache
|
||||||
if not ngx.var.skyd_disk_cache_enabled then
|
# if not ngx.var.skyd_disk_cache_enabled then
|
||||||
local httpc = require("resty.http").new()
|
# local httpc = require("resty.http").new()
|
||||||
|
#
|
||||||
-- detect whether requested skylink is v2
|
# -- detect whether requested skylink is v2
|
||||||
local isBase32v2 = string.len(ngx.var.skylink) == 55 and string.sub(ngx.var.skylink, 0, 2) == "04"
|
# local isBase32v2 = string.len(ngx.var.skylink) == 55 and string.sub(ngx.var.skylink, 0, 2) == "04"
|
||||||
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
|
||||||
-- 10.10.10.10 points to sia service (alias not available when using resty-http)
|
# -- 10.10.10.10 points to sia service (alias not available when using resty-http)
|
||||||
local res, err = httpc:request_uri("http://10.10.10.10:9980/skynet/resolve/" .. ngx.var.skylink_v2, {
|
# local res, err = httpc:request_uri("http://10.10.10.10:9980/skynet/resolve/" .. ngx.var.skylink_v2, {
|
||||||
headers = { ["User-Agent"] = "Sia-Agent" }
|
# headers = { ["User-Agent"] = "Sia-Agent" }
|
||||||
})
|
# })
|
||||||
|
#
|
||||||
-- print error and exit with 500 or exit with response if status is not 200
|
# -- print error and exit with 500 or exit with response if status is not 200
|
||||||
if err or (res and res.status ~= ngx.HTTP_OK) then
|
# if err or (res and res.status ~= ngx.HTTP_OK) then
|
||||||
ngx.status = (err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status
|
# ngx.status = (err and ngx.HTTP_INTERNAL_SERVER_ERROR) or res.status
|
||||||
ngx.header["content-type"] = "text/plain"
|
# ngx.header["content-type"] = "text/plain"
|
||||||
ngx.say(err or res.body)
|
# ngx.say(err or res.body)
|
||||||
return ngx.exit(ngx.status)
|
# return ngx.exit(ngx.status)
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
local json = require('cjson')
|
# local json = require('cjson')
|
||||||
local resolve = json.decode(res.body)
|
# local resolve = json.decode(res.body)
|
||||||
ngx.var.skylink_v1 = resolve.skylink
|
# ngx.var.skylink_v1 = resolve.skylink
|
||||||
ngx.var.skynet_proof = res.headers["Skynet-Proof"]
|
# ngx.var.skynet_proof = res.headers["Skynet-Proof"]
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
-- check if skylink v1 is present on blocklist (compare hashes)
|
# -- check if skylink v1 is present on blocklist (compare hashes)
|
||||||
if require("skynet.blocklist").is_blocked(ngx.var.skylink_v1) then
|
# if require("skynet.blocklist").is_blocked(ngx.var.skylink_v1) then
|
||||||
return require("skynet.blocklist").exit_illegal()
|
# return require("skynet.blocklist").exit_illegal()
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
-- if skylink is found on nocache list then set internal nocache variable
|
# -- if skylink is found on nocache list then set internal nocache variable
|
||||||
-- to tell nginx that it should not try and cache this file (too large)
|
# -- to tell nginx that it should not try and cache this file (too large)
|
||||||
if ngx.shared.nocache:get(ngx.var.skylink_v1) then
|
# if ngx.shared.nocache:get(ngx.var.skylink_v1) then
|
||||||
ngx.var.nocache = "1"
|
# ngx.var.nocache = "1"
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
if require("skynet.account").accounts_enabled() then
|
if require("skynet.account").accounts_enabled() then
|
||||||
-- check if portal is in authenticated only mode
|
-- check if portal is in authenticated only mode
|
||||||
|
|
Reference in New Issue