You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes Ingress Controller缓存异常:X-Cache-Status始终为Bypass

Nginx缓存返回BYPASS的解决配置

1. 允许带Authorization/Cookie的请求被缓存

Nginx默认会跳过包含Authorization或Cookie请求头的请求缓存,需根据业务需求调整:

  • 公共内容(无需按用户区分):忽略请求头,统一缓存相同URI的内容
    proxy_ignore_headers Authorization Cookie;
    proxy_cache_key $uri$args;
    
  • 用户专属内容:将请求头纳入缓存键,按用户维度缓存
    proxy_cache_key $uri$args$http_cookie;
    

2. 修正响应头的缓存控制

后端返回的Cache-Control头若包含no-cache/no-store/private,会阻止Nginx缓存响应:

  • 检查后端响应的Cache-Control,确保设置为public并指定缓存时长,例如Cache-Control: public, max-age=3600
  • 若无法修改后端,可在Nginx中强制覆盖:
    proxy_ignore_headers Cache-Control;
    add_header Cache-Control "public, max-age=3600";
    proxy_cache_valid 200 3600s;
    

3. 验证Ingress缓存规则关联

确保Ingress配置正确关联了static-cache缓存池:

  • 检查Ingress注解是否包含:nginx.ingress.kubernetes.io/proxy-cache: "static-cache"
  • 确认对应路径的Nginx配置块中存在proxy_cache static-cache;

4. 检查其他缓存限制

  • 仅GET/HEAD请求会被默认缓存,若需缓存其他方法(如POST),添加:proxy_cache_methods GET HEAD POST;
  • 登录Nginx Pod检查缓存目录权限:ls -ld /tmp/nginx_cache,确保Nginx进程有读写权限

内容的提问来源于stack exchange,提问作者MinistrBob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 15:15:00