From f1bf2d75c23138459ddca512570b7f967961b5b5 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Thu, 5 Aug 2021 14:34:00 +0200 Subject: [PATCH 1/2] use include file to skip unnecessary proxy --- docker/nginx/conf.d/client.conf | 32 ++----------------- .../conf.d/include/location-skynet-registry | 24 ++++++++++++++ 2 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 docker/nginx/conf.d/include/location-skynet-registry diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index fc978e74..b65ad0e5 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -245,45 +245,19 @@ server { # 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 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 - access_log off; # do not log traffic 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_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_pass http://127.0.0.1/skynet/registry$is_args$args; } location /skynet/registry { - 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 - } + include /etc/nginx/conf.d/include/location-skynet-registry; } location /skynet/skyfile { diff --git a/docker/nginx/conf.d/include/location-skynet-registry b/docker/nginx/conf.d/include/location-skynet-registry new file mode 100644 index 00000000..c0c00d00 --- /dev/null +++ b/docker/nginx/conf.d/include/location-skynet-registry @@ -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 +} \ No newline at end of file From 4a9828d6fb39b55d396b0192bad7f7ca13a8b7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Thu, 5 Aug 2021 14:46:04 +0200 Subject: [PATCH 2/2] newline --- docker/nginx/conf.d/include/location-skynet-registry | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/nginx/conf.d/include/location-skynet-registry b/docker/nginx/conf.d/include/location-skynet-registry index c0c00d00..31f6efe5 100644 --- a/docker/nginx/conf.d/include/location-skynet-registry +++ b/docker/nginx/conf.d/include/location-skynet-registry @@ -21,4 +21,4 @@ access_by_lua_block { ngx.sleep(limits.registry / 1000) end end -} \ No newline at end of file +}