@@ -35,6 +35,14 @@ http {
35
35
default $host ;
36
36
}
37
37
38
+ # A map to enable authentication to some specific docker hosts.
39
+ # To use this, mount a volume in docker.
40
+
41
+ map $host $dockerAuth {
42
+ include /etc/nginx/docker.auth.*.map;
43
+ default "" ;
44
+ }
45
+
38
46
# These maps parse the original Host and URI from a /forcecache redirect.
39
47
map $request_uri $realHost {
40
48
~ /forcecacheinsecure/([^:/]+)/originalwas(/.+) $ 1;
@@ -74,22 +82,35 @@ http {
74
82
if ($request_method = DELETE) {
75
83
return 405 ;
76
84
}
77
-
85
+
78
86
proxy_read_timeout 900 ;
79
87
80
88
# Use cache locking, with a huge timeout, so that multiple Docker clients asking for the same blob at the same time
81
89
# will wait for the first to finish instead of doing multiple upstream requests.
82
90
proxy_cache_lock on;
83
91
proxy_cache_lock_timeout 120s;
84
- proxy_cache_valid 200 301 302 60d ; # Cache all 200, 301, and 302 for 60 days.
92
+
93
+ # Cache all 200, 301, 302, and 307 (emitted by private registries) for 60 days.
94
+ proxy_cache_valid 200 301 302 307 60d ;
95
+
96
+ # Some extra settings to maximize cache hits and efficiency
85
97
proxy_force_ranges on;
86
98
proxy_ignore_client_abort on ;
87
99
proxy_cache_revalidate on;
88
100
101
+ # Hide/ignore headers from caching. S3 especially likes to send Expires headers in the past in some situations.
102
+ proxy_hide_header Set-Cookie;
103
+ proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
104
+
105
+ # Block API v1. We dont know how to handle these.
106
+ # Docker-client should start with v2 and fallback to v1 if something fails, for example, if authentication failed to a protected v2 resource.
107
+ location /v1 {
108
+ return 405 ;
109
+ }
110
+
89
111
# don't cache mutable entity /v2/<name>/manifests/<reference> (unless the reference is a digest)
90
112
location ~ ^/v2/[^\/]+/manifests/(?![A-Fa-f0-9_+.-]+:) {
91
113
proxy_pass https://$targetHost ;
92
- add_header X-Eh-Aqui $targetHost ;
93
114
}
94
115
95
116
# don't cache mutable entity /v2/<name>/tags/list
@@ -122,6 +143,11 @@ http {
122
143
location /forcecachesecure {
123
144
proxy_pass https://$realHost$realPath ;
124
145
proxy_cache cache;
146
+
147
+ # Change the cache key, so that we can cache signed S3 requests and such. Only host and path are considered.
148
+ proxy_cache_key $proxy_host$uri ;
149
+
150
+ # Some debugging headers. Not important
125
151
add_header X-Docker-Caching-Proxy-Real-Proto https;
126
152
add_header X-Docker-Caching-Proxy-Real-Host $realHost ;
127
153
add_header X-Docker-Caching-Proxy-Real-Path $realPath ;
@@ -132,9 +158,14 @@ http {
132
158
location /forcecacheinsecure {
133
159
proxy_pass http://$realHost$realPath ;
134
160
proxy_cache cache;
161
+
162
+ # Change the cache key, so that we can cache signed S3 requests and such. Only host and path are considered.
163
+ proxy_cache_key $proxy_host$uri ;
164
+
165
+ # Some debugging headers. Not important
135
166
add_header X-Docker-Caching-Proxy-Real-Proto http;
136
167
add_header X-Docker-Caching-Proxy-Real-Host $realHost ;
137
168
add_header X-Docker-Caching-Proxy-Real-Path $realPath ;
138
169
}
139
170
}
140
- }
171
+ }
0 commit comments