最明确信号是日志中$upstream_cache_status字段始终为空或未出现;需确认log_format含该变量、location启用对应access_log、proxy_cache指令存在且keys_zone匹配、proxy_pass有效执行,并可通过add_header X-Cache-Status验证。

直接看日志里 $upstream_cache_status 字段是否始终为空或根本不出现在日志中,这是 proxy_cache 未启用的最明确信号。
检查 access_log 是否输出了缓存状态
如果配置里没加 log_format 包含 $upstream_cache_status,或者对应 location 没启用该日志格式,你就看不到任何缓存行为痕迹:
- 确认 http 块中有类似定义:
log_format cache '$remote_addr - $upstream_cache_status $time_local "$request" $status $body_bytes_sent'; - 确认目标 location 中启用了它:
access_log /var/log/nginx/cache.log cache; - 重启 Nginx 后发请求,再查日志文件——若整行里完全没出现
HIT/MISS等值,大概率是 proxy_cache 根本没配或没生效
确认 location 中是否漏写了 proxy_cache 指令
proxy_cache_path 只是声明缓存区,真正启用缓存必须在具体 location 里显式调用:
安装并运行 Aperture(Lightning Labs 的 L402 闪电反向代理),用于创建 L402 付费墙、配置付费 API 端点、为其他代理托管付费内容或测试 L402 认证流程。
- 检查该 location 是否有
proxy_cache my_cache;(其中my_cache必须与 proxy_cache_path 的 keys_zone 名称一致) - 常见错误:只在 http 或 server 块写了 proxy_cache_path,但所有 location 都没写 proxy_cache,结果缓存形同虚设
- 注意:proxy_cache 不支持继承,必须每个需要缓存的 location 单独配置
验证 proxy_pass 是否存在且位置正确
proxy_cache 依赖 proxy_pass 才能工作;没有反向代理,缓存无从谈起:
- 该 location 必须包含
proxy_pass,且不能被 if、rewrite 或其他指令提前终止流程 - 典型陷阱:location 内先写了
return 302或error_page跳转,导致 proxy_pass 不执行,proxy_cache 自然无效 - 用
curl -I看响应头是否有后端地址(如 Server: nginx + X-Powered-By),确认确实走到了 proxy_pass
用 curl 和响应头快速交叉验证
即使没改日志,也能通过响应头判断缓存是否启用:
- 在 location 中加一句:
add_header X-Cache-Status $upstream_cache_status; - 重启后执行
curl -I http://your-domain/path - 如果响应头里压根没有
X-Cache-Status,说明该 location 没加载到 proxy_cache 相关逻辑;如果有但值为空,说明 proxy_cache 指令缺失或 keys_zone 名称不匹配

















