add request method and upstream time to logging; add cache status header; helps investigate #54

pull/56/head
Ricardo Pardini 2020-10-30 00:14:29 +01:00
parent 78f96ffe92
commit ffc7540f43
1 changed files with 16 additions and 10 deletions

View File

@ -35,8 +35,8 @@ http {
'"upstream_http_location":"$upstream_http_location",'
'"upstream_cache_status":"$upstream_cache_status",'
'"http_authorization":"$http_authorization",'
'}';
'}';
log_format debug_proxy escape=json
'{'
'"access_time":"$time_local",'
@ -56,20 +56,22 @@ http {
'"upstream_http_location":"$upstream_http_location",'
'"upstream_cache_status":"$upstream_cache_status",'
'"http_authorization":"$http_authorization",'
'}';
'}';
log_format tweaked escape=json
'{'
'"access_time":"$time_local",'
'"upstream_cache_status":"$upstream_cache_status",'
'"method":"$request_method",'
'"uri":"$uri",'
'"status":"$status",'
'"bytes_sent":"$body_bytes_sent",'
'"upstream_response_time":"$upstream_response_time",'
'"host":"$host",'
'"proxy_host":"$proxy_host",'
'"upstream":"$upstream_addr"'
'}';
keepalive_timeout 300;
gzip off;
@ -199,6 +201,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# Do some tweaked logging.
access_log /var/log/nginx/access.log tweaked;
# Send upstream status as header
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
# Use the generated certificates, they contain names for all the proxied registries.
ssl_certificate /certs/fullchain.pem;
ssl_certificate_key /certs/web.key;
@ -263,8 +268,9 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects;
}
# For manifest requests by digest, do cache, and treat redirects.
# These are some of the requests that DockerHub will throttle.
location ~ ^/v2/(.*)/manifests/sha256:(.*) {
proxy_pass https://$targetHost;
proxy_cache cache;
@ -272,9 +278,10 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects;
}
# Cache manifest requests that are not by digest (e.g. tags)
# 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/ {
proxy_pass https://$targetHost;
proxy_cache cache;
@ -284,7 +291,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
proxy_cache_valid 1s;
error_page 301 302 307 = @handle_redirects;
}
# 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/ {
@ -296,7 +303,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
proxy_cache_valid 1s;
error_page 301 302 307 = @handle_redirects;
}
location @handle_redirects {
#store the current state of the world so we can reuse it in a minute
# We need to capture these values now, because as soon as we invoke
@ -322,7 +329,6 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
location / {
proxy_pass https://$targetHost;
proxy_cache off;
add_header X-Docker-Caching-Proxy-Debug-Cache "no:default";
}
}
}