add request_type logging and headers; values are blob-by-digest, manifest-by-digest, manifest-mutable, blob-mutable

cache-manifests-tiers
Ricardo Pardini 2020-10-30 12:33:41 +01:00
parent 1856d821fc
commit 8524e376c1
1 changed files with 15 additions and 0 deletions

View File

@ -64,6 +64,7 @@ http {
'"upstream_cache_status":"$upstream_cache_status",'
'"method":"$request_method",'
'"uri":"$uri",'
'"request_type":"$docker_proxy_request_type",'
'"status":"$status",'
'"bytes_sent":"$body_bytes_sent",'
'"upstream_response_time":"$upstream_response_time",'
@ -135,6 +136,7 @@ http {
# dont log the CONNECT proxy.
#access_log /var/log/nginx/access.log debug_proxy;
access_log off;
set $docker_proxy_request_type "unknown-connect";
proxy_connect;
proxy_connect_address $interceptedHost;
@ -201,6 +203,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# Do some tweaked logging.
access_log /var/log/nginx/access.log tweaked;
set $docker_proxy_request_type "unknown";
# Send upstream status as header
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
@ -263,6 +266,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# For blob requests by digest, do cache, and treat redirects.
location ~ ^/v2/(.*)/blobs/sha256:(.*) {
set $docker_proxy_request_type "blob-by-digest";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
@ -273,6 +279,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# For manifest requests by digest, do cache, and treat redirects.
# These are some of the requests that DockerHub will throttle.
location ~ ^/v2/(.*)/manifests/sha256:(.*) {
set $docker_proxy_request_type "manifest-by-digest";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
@ -284,6 +293,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
# These are some of the requests that DockerHub will throttle.
location ~ ^/v2/(.*)/manifests/ {
set $docker_proxy_request_type "manifest-mutable";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
@ -296,6 +308,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# Cache blobs requests that are not by digest
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
location ~ ^/v2/(.*)/blobs/ {
set $docker_proxy_request_type "blob-mutable";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;