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..31f6efe5 --- /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 +}