Merge remote-tracking branch 'origin/master' into pin-endpoint

This commit is contained in:
Karol Wypchlo 2021-06-04 13:21:47 +02:00
commit 3cc3685273
2 changed files with 30 additions and 30 deletions

View File

@ -119,33 +119,6 @@ server {
location /skynet/stats { location /skynet/stats {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/cors;
set $response_body ''; # we need a variable for full response body (not chuncked)
# modify the response to add numfiles and totalsize to account for node rotation
# example prevstats.lua: 'return { numfiles = 12345, totalsize = 123456789 }'
body_filter_by_lua_block {
local file_exists = io.open("/data/nginx/skynet/prevstats.lua")
if file_exists then
file_exists.close()
-- because response data is chunked, we need to concat ngx.arg[1] until
-- last chunk is received (when ngx.arg[2] is set to true)
ngx.var.response_body = ngx.var.response_body .. ngx.arg[1]
if ngx.arg[2] then
local json = require('cjson')
local prevstats = require('/data/nginx/skynet/prevstats')
local stats = json.decode(ngx.var.response_body)
stats.uploadstats.numfiles = stats.uploadstats.numfiles + prevstats.numfiles
stats.uploadstats.totalsize = stats.uploadstats.totalsize + prevstats.totalsize
ngx.arg[1] = json.encode(stats)
else
-- do not send any data in this chunk (wait for last chunk)
ngx.arg[1] = nil
end
end
}
proxy_cache skynet; proxy_cache skynet;
proxy_cache_valid any 1m; # cache stats for 1 minute proxy_cache_valid any 1m; # cache stats for 1 minute
proxy_set_header User-Agent: Sia-Agent; proxy_set_header User-Agent: Sia-Agent;
@ -335,7 +308,11 @@ server {
limit_conn upload_conn_rl 1; limit_conn upload_conn_rl 1;
client_max_body_size 1000M; # make sure to limit the size of upload to a sane value client_max_body_size 1000M; # make sure to limit the size of upload to a sane value
# increase request timeouts
proxy_read_timeout 600; proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_request_buffering off; # stream uploaded files through the proxy as it comes in proxy_request_buffering off; # stream uploaded files through the proxy as it comes in
proxy_set_header Expect $http_expect; proxy_set_header Expect $http_expect;
proxy_set_header User-Agent: Sia-Agent; proxy_set_header User-Agent: Sia-Agent;
@ -362,7 +339,11 @@ server {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/cors;
client_max_body_size 50M; # tus chunks size is 40M + leaving 10M of breathing room client_max_body_size 50M; # tus chunks size is 40M + leaving 10M of breathing room
# increase request timeouts
proxy_read_timeout 600; proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_request_buffering off; # stream uploaded files through the proxy as it comes in proxy_request_buffering off; # stream uploaded files through the proxy as it comes in
proxy_set_header Expect $http_expect; proxy_set_header Expect $http_expect;
@ -390,6 +371,13 @@ server {
proxy_pass http://siad; proxy_pass http://siad;
} }
location /skynet/resolve {
include /etc/nginx/conf.d/include/cors;
proxy_set_header User-Agent: Sia-Agent;
proxy_pass http://siad;
}
location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" { location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" {
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;
@ -409,13 +397,25 @@ server {
set $skylink $2; set $skylink $2;
set $path $3; set $path $3;
# v2 support
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
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
ngx.var.nocache = 1 # nginx expects 0/1 for boolean 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)
ngx.var.skylink_v1 = resolve.skylink
else
ngx.say(res.body)
ngx.exit(res.status)
end
end end
-- this block runs only when accounts are enabled -- this block runs only when accounts are enabled
@ -432,7 +432,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 {

View File

@ -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