From 399ccfc351e99fde9958da0f8e977f70ade2ffa0 Mon Sep 17 00:00:00 2001 From: Aaron Spettl Date: Fri, 23 Apr 2021 19:44:52 +0200 Subject: [PATCH] Disable conversion of HEAD method to GET --- nginx.conf | 12 +++++++++++- nginx.manifest.common.conf | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nginx.conf b/nginx.conf index 897628e..8eccdd2 100644 --- a/nginx.conf +++ b/nginx.conf @@ -240,6 +240,16 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/" proxy_ignore_client_abort on; proxy_cache_revalidate on; + # Avoid conversion of HEAD method to GET + proxy_cache_convert_head off; + # HEAD requests are to be cached separately from GET, so they need a different cache key. + # To avoid a breaking change in cache keys (which would invalidate existing caches), we keep the normal URI + # for GET requests as key, but use a prefix for HEAD. + set $docker_proxy_cache_prefix ""; + if ($request_method = HEAD) { + set $docker_proxy_cache_prefix "HEAD:"; + } + # Hide/ignore headers from caching. S3 especially likes to send Expires headers in the past in some situations. proxy_hide_header Set-Cookie; proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; @@ -303,7 +313,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/" proxy_cache cache; # But we store the result with the cache key of the original request URI # so that future clients don't need to follow the redirect too - proxy_cache_key $original_uri; + proxy_cache_key $docker_proxy_cache_prefix$original_uri; } # by default, dont cache anything. diff --git a/nginx.manifest.common.conf b/nginx.manifest.common.conf index 69d809c..1be4289 100644 --- a/nginx.manifest.common.conf +++ b/nginx.manifest.common.conf @@ -3,6 +3,6 @@ add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type"; proxy_pass https://$targetHost; proxy_cache cache; - proxy_cache_key $uri; + proxy_cache_key $docker_proxy_cache_prefix$uri; proxy_intercept_errors on; error_page 301 302 307 = @handle_redirects;