Skip to content

Commit 6444380

Browse files
authored
Cache immutable URLs and handle outages (#51)
Cache immutable URLs and handle outages 1. Changes the blob cache to only cache by digest 2. Adds caching for manifests requested by digest 3. Cache but invalidate immediately (after 1s) mutable requests 4. Use invalidated cache (from 3) if the backend is down or 403 unauthorized
1 parent 1ecf949 commit 6444380

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

nginx.conf

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,48 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
224224
return 405 "docker-registry-proxy: docker is trying to use v1 API. Either the image does not exist upstream, or you need to configure docker-registry-proxy to authenticate against $host";
225225
}
226226

227-
# for the /v2/..../blobs/.... URIs, do cache, and treat redirects.
227+
# For blob requests by digest, do cache, and treat redirects.
228+
location ~ ^/v2/(.*)/blobs/sha256:(.*) {
229+
proxy_pass https://$targetHost;
230+
proxy_cache cache;
231+
proxy_cache_key $uri;
232+
proxy_intercept_errors on;
233+
error_page 301 302 307 = @handle_redirects;
234+
}
235+
236+
# For manifest requests by digest, do cache, and treat redirects.
237+
location ~ ^/v2/(.*)/manifests/sha256:(.*) {
238+
proxy_pass https://$targetHost;
239+
proxy_cache cache;
240+
proxy_cache_key $uri;
241+
proxy_intercept_errors on;
242+
error_page 301 302 307 = @handle_redirects;
243+
}
244+
245+
# Cache manifest requests that are not by digest (e.g. tags)
246+
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
247+
location ~ ^/v2/(.*)/manifests/ {
248+
proxy_pass https://$targetHost;
249+
proxy_cache cache;
250+
proxy_cache_key $uri;
251+
proxy_intercept_errors on;
252+
proxy_cache_use_stale error timeout http_500 http_502 http_504 http_403;
253+
proxy_cache_valid 1s;
254+
error_page 301 302 307 = @handle_redirects;
255+
}
256+
257+
# Cache blobs requests that are not by digest
258+
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
228259
location ~ ^/v2/(.*)/blobs/ {
229260
proxy_pass https://$targetHost;
230261
proxy_cache cache;
231262
proxy_cache_key $uri;
232263
proxy_intercept_errors on;
264+
proxy_cache_use_stale error timeout http_500 http_502 http_504 http_403;
265+
proxy_cache_valid 1s;
233266
error_page 301 302 307 = @handle_redirects;
234267
}
235-
268+
236269
location @handle_redirects {
237270
#store the current state of the world so we can reuse it in a minute
238271
# We need to capture these values now, because as soon as we invoke

0 commit comments

Comments
 (0)