Merge pull request #1053 from SkynetLabs/fix-issue-with-http-1.1-response-buffering

use include file to skip unnecessary proxy
This commit is contained in:
firyx 2021-08-05 14:47:40 +02:00 committed by GitHub
commit 698f7cb113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 29 deletions

View File

@ -245,45 +245,19 @@ server {
# it is not suitable for every registry call but some requests might be cached # it is not suitable for every registry call but some requests might be cached
# and we are using it currently for caching registry resolutions from /hns calls # and we are using it currently for caching registry resolutions from /hns calls
location /skynet/registry/cached { location /skynet/registry/cached {
include /etc/nginx/conf.d/include/proxy-pass-internal; include /etc/nginx/conf.d/include/location-skynet-registry;
internal; # internal endpoint only internal; # internal endpoint only
access_log off; # do not log traffic
proxy_cache skynet; proxy_cache skynet;
proxy_cache_key publickey=$arg_publickey&datakey=$arg_datakey; # cache based on publickey and datakey proxy_cache_key $args; # cache based on publickey and datakey args
proxy_cache_valid 200 30s; # cache only 200 responses and only for 30 seconds proxy_cache_valid 200 30s; # cache only 200 responses and only for 30 seconds
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
proxy_cache_bypass $cookie_nocache $arg_nocache; # add cache bypass option proxy_cache_bypass $cookie_nocache $arg_nocache; # add cache bypass option
proxy_pass http://127.0.0.1/skynet/registry$is_args$args;
} }
location /skynet/registry { location /skynet/registry {
include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/location-skynet-registry;
include /etc/nginx/conf.d/include/sia-auth;
include /etc/nginx/conf.d/include/track-registry;
limit_req zone=registry_access_by_ip burst=600 nodelay;
limit_req zone=registry_access_by_ip_throttled burst=200 nodelay;
proxy_set_header User-Agent: Sia-Agent;
proxy_read_timeout 600; # siad should timeout with 404 after 5 minutes
proxy_pass http://siad/skynet/registry;
access_by_lua_block {
-- this block runs only when accounts are enabled
if os.getenv("ACCOUNTS_ENABLED") ~= "true" then return end
local res = ngx.location.capture("/accounts/user/limits", { copy_all_vars = true })
if res.status == ngx.HTTP_OK then
local json = require('cjson')
local limits = json.decode(res.body)
if limits.registry > 0 then
ngx.sleep(limits.registry / 1000)
end
end
}
} }
location /skynet/skyfile { location /skynet/skyfile {

View File

@ -0,0 +1,24 @@
include /etc/nginx/conf.d/include/cors;
include /etc/nginx/conf.d/include/sia-auth;
include /etc/nginx/conf.d/include/track-registry;
limit_req zone=registry_access_by_ip burst=600 nodelay;
limit_req zone=registry_access_by_ip_throttled burst=200 nodelay;
proxy_set_header User-Agent: Sia-Agent;
proxy_read_timeout 600; # siad should timeout with 404 after 5 minutes
proxy_pass http://siad/skynet/registry;
access_by_lua_block {
-- this block runs only when accounts are enabled
if os.getenv("ACCOUNTS_ENABLED") ~= "true" then return end
local res = ngx.location.capture("/accounts/user/limits", { copy_all_vars = true })
if res.status == ngx.HTTP_OK then
local json = require('cjson')
local limits = json.decode(res.body)
if limits.registry > 0 then
ngx.sleep(limits.registry / 1000)
end
end
}