1
1
user nginx;
2
2
worker_processes auto;
3
3
4
- error_log /var/log/nginx/error.log warn ;
4
+ # error log config comes from external file created by entrypoint, to toggle debug on/off.
5
+ include /etc/nginx/error.log.debug.warn;
6
+
5
7
pid /var/run/nginx.pid;
6
8
7
9
events {
@@ -13,28 +15,28 @@ http {
13
15
include /etc/nginx/mime.types;
14
16
default_type application/octet-stream;
15
17
16
- # Use a debug-oriented logging format.
18
+ # Use a debug-oriented logging format.
17
19
log_format debugging '$remote_addr - $remote_user [$time_local ] "$request " '
18
20
'$status $body_bytes_sent '
19
21
'"HOST: $host " "UPSTREAM: $upstream_addr " '
20
22
'"UPSTREAM-STATUS: $upstream_status " '
21
23
'"SSL-PROTO: $ssl_protocol " '
22
- '"CONNECT-HOST: $connect_host " "CONNECT-PORT: $connect_port " "CONNECT-ADDR: $connect_addr " '
24
+ '"CONNECT-HOST: $connect_host " "CONNECT-PORT: $connect_port " "CONNECT-ADDR: $connect_addr " "INTERCEPTED: $interceptedHost " '
23
25
'"PROXY-HOST: $proxy_host " "UPSTREAM-REDIRECT: $upstream_http_location " "CACHE-STATUS: $upstream_cache_status " '
24
26
'"AUTH: $http_authorization " ' ;
25
-
27
+
26
28
log_format tweaked '$upstream_cache_status [$time_local ] "$uri " '
27
29
'$status $body_bytes_sent '
28
30
'"HOST:$host " '
29
31
'"PROXY-HOST:$proxy_host " "UPSTREAM:$upstream_addr " ' ;
30
-
32
+
31
33
keepalive_timeout 300 ;
32
34
gzip off ;
33
35
34
36
# The cache directory. This can get huge. Better to use a Docker volume pointing here!
35
37
# Set to 32gb which should be enough
36
38
proxy_cache_path /docker_mirror_cache levels=1:2 max_size=32g inactive=60d keys_zone=cache:10m use_temp_path=off;
37
-
39
+
38
40
# Just in case you want to rewrite some hosts. Default maps directly.
39
41
map $host $targetHost {
40
42
hostnames;
48
50
include /etc/nginx/docker.auth.map;
49
51
default "" ;
50
52
}
51
-
53
+
52
54
# Map to decide which hosts get directed to the caching portion.
53
55
# This is automatically generated from the list of cached registries, plus a few fixed hosts
54
56
# By default, we don't intercept, allowing free flow of non-registry traffic
@@ -57,13 +59,13 @@ http {
57
59
include /etc/nginx/docker.intercept.map;
58
60
default "$connect_host :443" ;
59
61
}
60
-
61
- map $dockerAuth $finalAuth {
62
+
63
+ map $dockerAuth $finalAuth {
62
64
"" "$http_authorization " ; # if empty, keep the original passed-in from the client
63
65
default "Basic $dockerAuth " ; # if not empty, add the Basic preamble to the auth
64
66
}
65
-
66
-
67
+
68
+
67
69
# These maps parse the original Host and URI from a /forcecache redirect.
68
70
map $request_uri $realHost {
69
71
~ /forcecacheinsecure/([^:/]+)/originalwas(/.+) $ 1;
@@ -76,43 +78,44 @@ http {
76
78
~ /forcecachesecure/([^:/]+)/originalwas(/.+) $ 2;
77
79
default "DID_NOT_MATCH_PATH" ;
78
80
}
79
-
80
-
81
+
82
+
81
83
# The proxy director layer, listens on 3128
82
84
server {
83
85
listen 3128 ;
84
86
server_name _;
85
-
87
+
86
88
# dont log the CONNECT proxy.
87
89
access_log off ;
88
-
90
+
89
91
proxy_connect;
90
92
proxy_connect_address $interceptedHost ;
91
93
proxy_max_temp_file_size 0 ;
92
-
94
+
93
95
# We need to resolve the real names of our proxied servers.
94
96
resolver 8.8.8.8 4.2.2.2 ipv6=off; # Avoid ipv6 addresses for now
95
97
96
98
# forward proxy for non-CONNECT request
97
99
location / {
98
100
return 403 "The docker caching proxy is working!" ;
99
101
}
100
-
102
+
101
103
location /ca.crt {
102
- alias /ca/ca.crt;
104
+ alias /ca/ca.crt;
103
105
}
104
106
105
107
# @TODO: add a dynamic root path that generates instructions for usage on docker clients
106
108
}
107
-
109
+
108
110
109
111
# The caching layer
110
112
server {
111
113
# Listen on both 80 and 443, for all hostnames.
114
+ # actually could be 443 or 444, depending on debug. this is now generated by the entrypoint.
112
115
listen 80 default_server ;
113
- listen 443 ssl default_server ;
116
+ include /etc/nginx/caching.layer.listen ;
114
117
server_name _;
115
-
118
+
116
119
# Do some tweaked logging.
117
120
access_log /var/log/nginx/access.log tweaked;
118
121
@@ -136,17 +139,17 @@ http {
136
139
if ($request_method = DELETE) {
137
140
return 405 "DELETE method is not allowed" ;
138
141
}
139
-
142
+
140
143
proxy_read_timeout 900 ;
141
-
142
- # Use cache locking, with a huge timeout, so that multiple Docker clients asking for the same blob at the same time
144
+
145
+ # Use cache locking, with a huge timeout, so that multiple Docker clients asking for the same blob at the same time
143
146
# will wait for the first to finish instead of doing multiple upstream requests.
144
147
proxy_cache_lock on;
145
148
proxy_cache_lock_timeout 120s;
146
149
147
150
# Cache all 200, 301, 302, and 307 (emitted by private registries) for 60 days.
148
- proxy_cache_valid 200 301 302 307 60d ;
149
-
151
+ proxy_cache_valid 200 301 302 307 60d ;
152
+
150
153
# Some extra settings to maximize cache hits and efficiency
151
154
proxy_force_ranges on;
152
155
proxy_ignore_client_abort on ;
@@ -155,13 +158,13 @@ http {
155
158
# Hide/ignore headers from caching. S3 especially likes to send Expires headers in the past in some situations.
156
159
proxy_hide_header Set-Cookie;
157
160
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
158
-
161
+
159
162
# Add the authentication info, if the map matched the target domain.
160
163
proxy_set_header Authorization $finalAuth ;
161
-
164
+
162
165
# This comes from a include file generated by the entrypoint.
163
166
include /etc/nginx/docker.verify.ssl.conf;
164
-
167
+
165
168
# Some debugging info
166
169
# add_header X-Docker-Caching-Proxy-Real-Host $realHost;
167
170
# add_header X-Docker-Caching-Proxy-Real-Path $realPath;
@@ -176,23 +179,35 @@ http {
176
179
# don't cache mutable entity /v2/<name>/manifests/<reference> (unless the reference is a digest)
177
180
location ~ ^/v2/[^\/]+/manifests/(?![A-Fa-f0-9_+.-]+:) {
178
181
proxy_pass https://$targetHost ;
182
+ add_header X-Docker-Caching-Proxy-Debug-Cache "no:manifests" ;
179
183
}
180
184
181
185
# don't cache mutable entity /v2/<name>/tags/list
182
186
location ~ ^/v2/[^\/]+/tags/list {
183
187
proxy_pass https://$targetHost ;
188
+ proxy_cache off ;
189
+ add_header X-Docker-Caching-Proxy-Debug-Cache "no:tagslist" ;
184
190
}
185
191
186
192
# don't cache mutable entity /v2/_catalog
187
193
location ~ ^/v2/_catalog$ {
188
194
proxy_pass https://$targetHost ;
195
+ proxy_cache off ;
196
+ add_header X-Docker-Caching-Proxy-Debug-Cache "no:catalog" ;
189
197
}
190
-
191
- # force cache of the first hit which is always /v2/ - even for 401 unauthorized.
198
+
199
+ # dont cache the first hit which is always /v2/
192
200
location = /v2/ {
193
201
proxy_pass https://$targetHost ;
194
- proxy_cache cache;
195
- proxy_cache_valid 200 301 302 307 401 60d ;
202
+ proxy_cache off ;
203
+ add_header X-Docker-Caching-Proxy-Debug-Cache "no:rootv2" ;
204
+ }
205
+
206
+ # dont cache /token (done against auth servers)
207
+ location = /token {
208
+ proxy_pass https://$targetHost ;
209
+ proxy_cache off ;
210
+ add_header X-Docker-Caching-Proxy-Debug-Cache "no:token" ;
196
211
}
197
212
198
213
# cache everything else
@@ -208,26 +223,33 @@ http {
208
223
# We to it twice, one for http and another for https.
209
224
proxy_redirect ~^https://([^:/]+)(/.+)$ https://docker.caching.proxy.internal/forcecachesecure/$1 /originalwas$2 ;
210
225
proxy_redirect ~^http://([^:/]+)(/.+)$ http://docker.caching.proxy.internal/forcecacheinsecure/$1 /originalwas$2 ;
226
+
227
+ add_header X-Docker-Caching-Proxy-Debug-Cache "yes:everythingelse" ;
211
228
}
212
229
213
230
# handling for the redirect case explained above, with https.
214
231
# The $realHost and $realPath variables come from a map defined at the top of this file.
215
232
location /forcecachesecure {
216
233
proxy_pass https://$realHost$realPath ;
217
234
proxy_cache cache;
218
-
235
+
219
236
# Change the cache key, so that we can cache signed S3 requests and such. Only host and path are considered.
220
237
proxy_cache_key $proxy_host$uri ;
238
+
239
+ add_header X-Docker-Caching-Proxy-Debug-Cache "yes:forcecachesecure" ;
240
+
221
241
}
222
242
223
243
# handling for the redirect case explained above, with http.
224
244
# The $realHost and $realPath variables come from a map defined at the top of this file.
225
245
location /forcecacheinsecure {
226
246
proxy_pass http://$realHost$realPath ;
227
247
proxy_cache cache;
228
-
248
+
229
249
# Change the cache key, so that we can cache signed S3 requests and such. Only host and path are considered.
230
250
proxy_cache_key $proxy_host$uri ;
251
+
252
+ add_header X-Docker-Caching-Proxy-Debug-Cache "yes:forcecacheinsecure" ;
231
253
}
232
254
}
233
255
}
0 commit comments