Skip to content

Commit a5dfe60

Browse files
committed
add request method; disable head conversion
1 parent b298a9e commit a5dfe60

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf
153153
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
154154
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
155155
set \$docker_proxy_request_type "manifest-primary";
156-
set \$cache_key \$uri;
156+
set \$request_method \$cache_key \$uri;
157157
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME};
158158
include "/etc/nginx/nginx.manifest.stale.conf";
159159
}
@@ -163,7 +163,7 @@ EOD
163163
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
164164
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
165165
set \$docker_proxy_request_type "manifest-secondary";
166-
set \$cache_key \$uri;
166+
set \$request_method \$cache_key \$uri;
167167
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME};
168168
include "/etc/nginx/nginx.manifest.stale.conf";
169169
}
@@ -173,7 +173,7 @@ EOD
173173
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
174174
location ~ ^/v2/(.*)/manifests/ {
175175
set \$docker_proxy_request_type "manifest-default";
176-
set \$cache_key \$uri;
176+
set \$request_method \$cache_key \$uri;
177177
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME};
178178
include "/etc/nginx/nginx.manifest.stale.conf";
179179
}
@@ -183,7 +183,7 @@ EOD
183183
# Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true
184184
location ~ ^/v2/(.*)/manifests/ {
185185
set \$docker_proxy_request_type "manifest-default-disabled";
186-
set \$cache_key \$uri;
186+
set \$request_method \$cache_key \$uri;
187187
proxy_cache_valid 0s;
188188
include "/etc/nginx/nginx.manifest.stale.conf";
189189
}

nginx.conf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
252252
proxy_ignore_client_abort on;
253253
proxy_cache_revalidate on;
254254

255+
# Avoid conversion of HEAD method to GET
256+
proxy_cache_convert_head off;
257+
255258
# Hide/ignore headers from caching. S3 especially likes to send Expires headers in the past in some situations.
256259
proxy_hide_header Set-Cookie;
257260
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
@@ -275,15 +278,15 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
275278
# For blob requests by digest, do cache, and treat redirects.
276279
location ~ ^/v2/(.*)/blobs/sha256:(.*) {
277280
set $docker_proxy_request_type "blob-by-digest";
278-
set $cache_key $2;
281+
set $cache_key $request_method$2;
279282
include "/etc/nginx/nginx.manifest.common.conf";
280283
}
281284

282285
# For manifest requests by digest, do cache, and treat redirects.
283286
# These are some of the requests that DockerHub will throttle.
284287
location ~ ^/v2/(.*)/manifests/sha256:(.*) {
285288
set $docker_proxy_request_type "manifest-by-digest";
286-
set $cache_key $uri;
289+
set $cache_key $request_method$uri;
287290
include "/etc/nginx/nginx.manifest.common.conf";
288291
}
289292

@@ -296,7 +299,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
296299
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
297300
location ~ ^/v2/(.*)/blobs/ {
298301
set $docker_proxy_request_type "blob-mutable";
299-
set $cache_key $uri;
302+
set $cache_key $request_method$uri;
300303
proxy_cache_valid 0s;
301304
include "/etc/nginx/nginx.manifest.stale.conf";
302305
}
@@ -307,6 +310,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
307310
# the proxy_* directives, these will disappear
308311
set $original_uri $uri;
309312
set $orig_loc $upstream_http_location;
313+
set $orig_cache_key $cache_key
310314
# Handle relative re-direct in Location header (as opposed to absolute)
311315
if ($upstream_http_location !~ "^http") {
312316
set $orig_loc "${scheme}://${host}${upstream_http_location}";
@@ -322,7 +326,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
322326
proxy_cache $cache;
323327
# But we store the result with the cache key of the original request URI
324328
# so that future clients don't need to follow the redirect too
325-
proxy_cache_key $original_uri$slice_range;
329+
proxy_cache_key $orig_cache_key$slice_range;
326330
}
327331

328332
# by default, dont cache anything.

0 commit comments

Comments
 (0)