2021-08-27 12:15:22 +00:00
|
|
|
include /etc/nginx/conf.d/include/cors;
|
|
|
|
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
|
|
|
|
|
2021-11-05 11:57:06 +00:00
|
|
|
# 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
|
2022-03-10 08:55:24 +00:00
|
|
|
set_by_lua_block $skylink { return require("skynet.skylink").parse(ngx.var.skylink) }
|
2021-11-05 11:57:06 +00:00
|
|
|
|
2022-03-14 17:45:04 +00:00
|
|
|
# variable for Skynet-Proof header that we need to inject
|
2021-08-27 12:15:22 +00:00
|
|
|
# into a response if the request was for skylink v2
|
|
|
|
set $skynet_proof '';
|
|
|
|
|
|
|
|
# default download rate to unlimited
|
|
|
|
set $limit_rate 0;
|
|
|
|
|
|
|
|
access_by_lua_block {
|
2022-03-14 17:45:04 +00:00
|
|
|
local accounts = require("skynet.account")
|
|
|
|
if accounts.accounts_enabled() then
|
2021-12-23 14:09:54 +00:00
|
|
|
-- check if portal is in authenticated only mode
|
2022-03-14 17:45:04 +00:00
|
|
|
if accounts.is_access_unauthorized() then
|
|
|
|
return accounts.exit_access_unauthorized()
|
2021-12-23 14:09:54 +00:00
|
|
|
end
|
2021-08-27 12:15:22 +00:00
|
|
|
|
2022-01-21 16:43:30 +00:00
|
|
|
-- check if portal is in subscription only mode
|
2022-03-14 17:45:04 +00:00
|
|
|
if accounts.is_access_forbidden() then
|
|
|
|
return accounts.exit_access_forbidden()
|
2022-01-21 16:43:30 +00:00
|
|
|
end
|
2021-08-27 12:15:22 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
header_filter_by_lua_block {
|
2022-02-25 14:24:09 +00:00
|
|
|
ngx.header["Skynet-Portal-Api"] = ngx.var.scheme .. "://" .. ngx.var.skynet_portal_domain
|
|
|
|
ngx.header["Skynet-Server-Api"] = ngx.var.scheme .. "://" .. ngx.var.skynet_server_domain
|
2021-08-27 12:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
limit_rate_after 512k;
|
|
|
|
limit_rate $limit_rate;
|
|
|
|
|
|
|
|
proxy_read_timeout 600;
|
|
|
|
proxy_set_header User-Agent: Sia-Agent;
|
|
|
|
|
2022-03-14 17:45:04 +00:00
|
|
|
# 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
|
2021-08-27 12:15:22 +00:00
|
|
|
# we need to rewrite the skylink v1 to skylink v2 in the location header with proxy_redirect
|
2022-03-15 09:51:25 +00:00
|
|
|
proxy_pass http://sia:9980/skynet/skylink/$skylink$path$is_args$args;
|