Files
ipass-plugin-cache/conf/nginx.cache.conf
T
ssw 43718bd0c4 iPass cache gateway 源码
容量管理: 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 容量管理章节
2026-09-21 09:25:11 +08:00

88 lines
4.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================================
# nginx.cache.conf —— 统一制品缓存网关 · 顶层配置
#
# vanilla nginx + ipass Rust 动态模块(plugin-cache)
#
# 本机回归:bash tests/cache/run.sh
# 生产部署:把本文件放到 nginx prefix 的 conf/ 下,同目录放
# server.cache.conf / cache-routes.conf / cache-common.conf /
# mime.types,启动即可;要对外 https 再加 conf/tls/*.conf。
#
# 数据面 = nginx 原生 proxy_cache(六生态各一个 zone,落本地盘);
# 管理面 = ipass plugin-cache(access 鉴权 + log 按生态记账 + 管理 API)。
#
# ⚠️ 上游地址/凭据**不在 conf 里**:全在 plugin-cache 的上游表
# (管理台「制品缓存」页 → data/cache-upstreams.json → 写穿共享内存)。
# conf 只出现 `$cache_*` 变量名,所以改上游不需要动 conf、不需要 reload。
#
# ⚠️ 因为 proxy_pass 是变量形式,`resolver` 是**必需**的:nginx 无法在配置
# 解析期把变量里的主机名解析成 IP,只能运行期查 DNS。缺 resolver 的表现是
# `/go/...` 一律 500(no resolver defined to resolve ...)。
#
# 本构建(build/build-nginx-ssl.sh)对齐 ipass 生产的 Dockerfile 参数:
# --with-pcre --with-http_ssl_module --with-http_realip_module
# 即 rewrite 模块与 SSL 都在编,所以本文件与 server.cache.conf /
# cache-routes.conf 里可以用 `return` / `rewrite` / `ssl_certificate`。
# ============================================================================
load_module /usr/local/nginx/modules/libipass_gateway.so;
worker_processes auto;
error_log /usr/local/nginx/logs/error.log info;
pid /usr/local/nginx/logs/nginx.pid;
# 初始管理员口令(不声明则会被 nginx 从环境中剥离)
env ADMIN_INIT_PASSWORD;
events {
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream; # 缺 Content-Type 时的兜底;
# API 响应由模块显式设 application/json
sendfile on;
keepalive_timeout 65;
# ========== 变量式上游的必需项 ==========
# proxy_pass $cache_target 里的主机名只能运行期解析(见文件头注释)。
# 两个国内解析器,30s 缓存;ipv6=off 避免拿到不可达的 AAAA 卡住连接。
resolver 223.5.5.5 119.29.29.29 valid=30s ipv6=off;
resolver_timeout 5s;
# ========== 可选 TLS(HTTPS)==========
# conf/tls/ 下放任意 *.conf(完整的 443/18098 server 块)即启用对应域名的
# HTTPS;目录为空或不存在时 include 空匹配,不影响启动。
# 模板见 conf/tls/cache.conf.example,说明见 conf/tls/README.md
include /usr/local/nginx/conf/tls/*.conf;
# ========== ipass 内核:共享内存 + 数据目录 ==========
# 一张共享内存表承载:上游表(cx:)/ 命中计数(cache:)/ 管理会话 / 限流窗口。
# 上游表条目数 = 路由数(个位数),10m 绰绰有余。
ipass_state state 10m;
ipass_data_dir /usr/local/nginx/data;
ipass_audit_dir /usr/local/nginx/audit;
# ========== 六类生态缓存区(本地盘热层)==========
# 各生态独立 zone,互不串档、独立上限;use_temp_path=off 省一次改名。
# ⚠️ cargo / pypi 各有两个 route 共用同一个 zone(索引 + 包本体):
# 这是刻意的——同一门语言的流量记在一起才看得懂,而 zone 内靠
# $cache_key 的 route 前缀天然分档,不会串。
proxy_cache_path /var/cache/ipass-cache/go levels=1:2 keys_zone=go:100m max_size=50g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/ipass-cache/cargo levels=1:2 keys_zone=cargo:100m max_size=50g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/ipass-cache/pypi levels=1:2 keys_zone=pypi:100m max_size=50g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/ipass-cache/npm levels=1:2 keys_zone=npm:100m max_size=50g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/ipass-cache/maven levels=1:2 keys_zone=maven:100m max_size=50g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/ipass-cache/docker levels=1:2 keys_zone=docker:200m max_size=200g inactive=7d use_temp_path=off;
# 命中率日志(排障用;真实指标由 plugin-cache 的共享内存计数器提供)
log_format cache '$remote_addr [$time_local] "$request" $status '
'$body_bytes_sent cache=$upstream_cache_status eco=$cache_eco '
'uri=$uri rt=$request_time';
access_log /usr/local/nginx/logs/cache.log cache;
include server.cache.conf;
}