@@ -18,7 +18,13 @@ http {
18
18
default_type application/octet-stream;
19
19
sendfile on ;
20
20
keepalive_timeout 65 ;
21
- proxy_cache_path /tmp/npm-cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
21
+ proxy_cache_path /tmp/npm/cache levels=1:2 keys_zone=NPM:10m inactive=90d max_size=5g;
22
+ proxy_temp_path /tmp/npm/temp;
23
+ proxy_cache_lock on;
24
+ log_format upstreamlog '$remote_addr - $remote_user [$time_local ] '
25
+ '"$request " $status $body_bytes_sent '
26
+ '"$http_referer " "$http_user_agent " "$upstream_cache_status "' ;
27
+ access_log logs/access.log upstreamlog;
22
28
server {
23
29
listen 4873 ;
24
30
set $npm_config_registry '' ;
@@ -27,27 +33,34 @@ http {
27
33
local upstream = os.getenv("npm_config_registry" )
28
34
-- escape . and - which have special meaning in Lua patterns
29
35
upstream = upstream:gsub("%." , "%%." ):gsub("%-" , "%%-" ):gsub("/+$" , "" )
30
- ngx.log(ngx.ERR, 'using upstream base:', upstream)
36
+ -- ngx.log(ngx.ERR, 'using upstream base:', upstream)
31
37
return upstream
32
38
}
33
39
set_by_lua_block $npm_config_registry {
34
40
local upstream = os.getenv("npm_config_registry"):gsub("/+$", "")
35
- ngx.log(ngx.ERR, ' using upstream server:', upstream)
41
+ -- ngx.log(ngx.ERR, ' using upstream server:', upstream)
36
42
return upstream
37
43
}
38
44
location ~ ^/.*\.tgz$ {
39
45
resolver 127.0.0.1 ipv6=off;
40
46
proxy_pass $npm_config_registry ;
41
- proxy_cache STATIC;
42
- proxy_cache_valid 200 1d;
47
+ proxy_cache NPM;
48
+ proxy_ignore_headers X-Accel-Redirect X-Accel-Expires X-Accel-Limit-Rate X-Accel-Buffering X-Accel-Charset Expires Cache-Control Set-Cookie Vary;
49
+ # npm package tarballs are NEVER supposed to change
50
+ proxy_cache_revalidate off;
51
+ proxy_cache_valid 200 90d;
43
52
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
44
53
}
45
54
location / {
46
55
resolver 127.0.0.1 ipv6=off;
47
56
proxy_pass $npm_config_registry ;
48
57
proxy_buffers 32 1m;
49
- proxy_cache STATIC;
50
- proxy_cache_valid 200 1d;
58
+ proxy_cache NPM;
59
+ # need nginx-1.11.10 for this, which isn' t in openresty yet:
60
+ # proxy_cache_background_update on;
61
+ proxy_cache_revalidate on;
62
+ # let our metadata be 20 minutes old, at most
63
+ proxy_cache_valid 200 20m ;
51
64
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
52
65
# need to disable encoding in order to be able to filter the response body
53
66
proxy_set_header Accept-Encoding "" ;
60
73
local upstream = ngx.var.upstream_base
61
74
-- need to construct URL because we may be proxying http<->https
62
75
local base = ngx.var.scheme .. '://' .. ngx.var.http_host
63
- ngx.log(ngx.ERR, "Modifying JSON of " .. ngx.var.uri .. " to replace ' " .. upstream .. " ' with ' " .. base .. " '")
76
+ -- ngx.log(ngx.ERR, "Modifying JSON of " .. ngx.var.uri .. " to replace '" .. upstream .. "' with '" .. base .. "' ")
64
77
ngx.arg[1] = string.gsub(ngx.arg[1], upstream, base)
65
78
}
66
79
}
0 commit comments