容量管理: zones.rs 直读 nginx file_cache 共享内存记账(双轴: 磁盘 + keys_zone 索引内存), ?scan=1 扫盘上限 20 万文件; POST /api/admin/cache/purge 整区清理(只删文件不删目录, 根治 [crit] mkdir failed); POST /api/admin/cache/invalidate 按制品精准失效(预览->确认两步式, glob/子串, 删除上限 5000/扫描上限 20 万); GET /api/admin/cache 新增 capacity 块; 前端容量面板 + 按制品失效工具条; 测试 test-cache-capacity.sh 48/48(容量 27 + 精准失效 21, 含 EXPECT_MIN 护栏与前端静态契约); docs 容量管理章节
106 lines
4.2 KiB
Plaintext
106 lines
4.2 KiB
Plaintext
# ============================================================================
|
||
# 统一制品缓存 · 本机自测配置(不加载 ipass 模块,纯 nginx proxy_cache)
|
||
#
|
||
# 验证对象:六类生态的「代理缓存」这一层本身(MISS→HIT / Range / PURGE /
|
||
# X-Cache-Status)。生产环境由 server.cache.conf 在每 location 加 `ipass_cache on`
|
||
# 接入 ipass 的身份/配额/命中计量,缓存引擎完全一致。
|
||
#
|
||
# 上游统一指向本机 mock_upstream.py(18999);按生态分 zone 与缓存键前缀,
|
||
# 各生态互不串档。PURGE 用 map 限制仅 127.0.0.1(无需 rewrite 模块)。
|
||
# ============================================================================
|
||
|
||
worker_processes 1;
|
||
error_log @RUN@/logs/error.log warn;
|
||
|
||
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
http {
|
||
default_type application/octet-stream;
|
||
access_log off;
|
||
|
||
|
||
# 六类生态各自的缓存区(热层=本地盘;S3 冷层预留见生产 conf)
|
||
proxy_cache_path @RUN@/cache/go levels=1:2 keys_zone=go:10m max_size=1g inactive=7d;
|
||
proxy_cache_path @RUN@/cache/cargo levels=1:2 keys_zone=cargo:10m max_size=1g inactive=7d;
|
||
proxy_cache_path @RUN@/cache/pypi levels=1:2 keys_zone=pypi:10m max_size=1g inactive=7d;
|
||
proxy_cache_path @RUN@/cache/npm levels=1:2 keys_zone=npm:10m max_size=1g inactive=7d;
|
||
proxy_cache_path @RUN@/cache/maven levels=1:2 keys_zone=maven:10m max_size=1g inactive=7d;
|
||
proxy_cache_path @RUN@/cache/docker levels=1:2 keys_zone=docker:10m max_size=5g inactive=7d;
|
||
|
||
# 假上游(确定性,支持 Range)
|
||
upstream mock { server 127.0.0.1:18999; }
|
||
|
||
server {
|
||
listen 127.0.0.1:18083;
|
||
server_name _;
|
||
|
||
# ---------- go (Go modules proxy) ----------
|
||
location /go/ {
|
||
proxy_pass http://mock/;
|
||
proxy_cache go;
|
||
proxy_cache_key $scheme$proxy_host$request_uri;
|
||
proxy_cache_valid 200 302 1h;
|
||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||
proxy_force_ranges on;
|
||
add_header X-Cache-Status $upstream_cache_status;
|
||
}
|
||
|
||
# ---------- cargo (Rust crates) ----------
|
||
location /cargo/ {
|
||
proxy_pass http://mock/;
|
||
proxy_cache cargo;
|
||
proxy_cache_key $scheme$proxy_host$request_uri;
|
||
proxy_cache_valid 200 302 1h;
|
||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||
proxy_force_ranges on;
|
||
add_header X-Cache-Status $upstream_cache_status;
|
||
}
|
||
|
||
# ---------- pypi (Python) ----------
|
||
location /pypi/ {
|
||
proxy_pass http://mock/;
|
||
proxy_cache pypi;
|
||
proxy_cache_key $scheme$proxy_host$request_uri;
|
||
proxy_cache_valid 200 302 1h;
|
||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||
proxy_force_ranges on;
|
||
add_header X-Cache-Status $upstream_cache_status;
|
||
}
|
||
|
||
# ---------- npm (Node) ----------
|
||
location /npm/ {
|
||
proxy_pass http://mock/;
|
||
proxy_cache npm;
|
||
proxy_cache_key $scheme$proxy_host$request_uri;
|
||
proxy_cache_valid 200 302 1h;
|
||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||
proxy_force_ranges on;
|
||
add_header X-Cache-Status $upstream_cache_status;
|
||
}
|
||
|
||
# ---------- maven (Java) ----------
|
||
location /maven/ {
|
||
proxy_pass http://mock/;
|
||
proxy_cache maven;
|
||
proxy_cache_key $scheme$proxy_host$request_uri;
|
||
proxy_cache_valid 200 302 1h;
|
||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||
proxy_force_ranges on;
|
||
add_header X-Cache-Status $upstream_cache_status;
|
||
}
|
||
|
||
# ---------- docker (OCI registry;生产含 token 透传,自测仅 GET 缓存) ----------
|
||
location /docker/ {
|
||
proxy_pass http://mock/;
|
||
proxy_cache docker;
|
||
proxy_cache_key $scheme$proxy_host$request_uri;
|
||
proxy_cache_valid 200 302 1h;
|
||
proxy_ignore_headers Cache-Control Expires Set-Cookie;
|
||
proxy_force_ranges on;
|
||
add_header X-Cache-Status $upstream_cache_status;
|
||
}
|
||
}
|
||
}
|