Cloudflare配置API防缓存规则后仍为Dynamic状态,如何获取BYPASS缓存状态
解决方法
- 调整页面规则优先级:Cloudflare页面规则按从上到下的顺序匹配,将你配置的API路径对应的缓存绕过规则拖动到所有缓存相关规则的最顶部,避免被低优先级规则覆盖配置。
- 修正规则内的缓存配置:在目标API的页面规则中,除了将「缓存级别」设置为「绕过」外,同步关闭规则内的「始终在线」功能,「浏览器缓存TTL」选择「遵循原点」即可,无需额外调整其他缓存项。
- 消除原点响应头冲突:你当前返回的响应头包含
cache-control: no-cache, no-store, max-age=0, must-revalidate这类强不缓存配置,会被Cloudflare默认判定为动态内容。你可以在页面规则中新增「修改响应头」配置,直接覆盖cache-control的值,或者禁用规则内的「原点缓存控制」开关,让Cloudflare规则优先级高于原点返回的头配置。 - 验证生效:配置完成后等待2~3分钟待规则全局同步,使用无痕模式发起请求即可看到
cf-cache-status: BYPASS的返回值。
你当前返回的完整响应头如下:
access-control-allow-methods: GET,OPTIONS alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400 cache-control: no-cache, no-store, max-age=0, must-revalidate cf-cache-status: DYNAMIC cf-ray: 698eeac5ae5640cf-CDG client-control: max-age=43200, s-max-age=43200 content-encoding: br content-type: application/json date: Mon, 04 Oct 2021 13:57:03 GMT expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" expires: 0 pragma: no-cache server: cloudflare strict-transport-security: max-age=31536000; includeSubDomains; preload vary: Origin,Access-Control-Request-Method,Access-Control-Request-Headers, Accept-Encoding x-content-type-options: nosniff x-frame-options: DENY x-xss-protection: 1; mode=block
你已完成的配置截图:
内容的提问来源于stack exchange,提问作者J. DEMARE
相关产品推荐
相关产品推荐

