服务器配置

页面关闭cloudflare压缩解决方法

我的站长站 2022-11-09 人阅读

使用了cloudflare后,前台页面默认是强制Gzip压缩的,就算你到cloudflare后台关闭了Brotli压缩开关,页面头部依旧会显示content encoding: gzip

页面关闭cloudflare压缩解决方法

这个属实是坑惨了我的站长站,一直以为关闭了服务器的GZIP和cloudflare后台的Brotli压缩开关,就应该不压缩了,让我还一度怀疑是不是宝塔的BUG,浪费了很长时间。

不得已只能排除法,最后发现是使用了cloudflare。不懂英语的我的站长站又去cloudflare手册翻,终于看到这篇文章的方法。

解决方法

cloudflare官方文档原文:https://support.cloudflare.com/hc/en-us/articles/200168396

What will Cloudflare compress?
In addition to Cloudflare's CDN caching static content and auto-minification of CSS, JS & HTML to speed up your site, Cloudflare also provides gzip and brotli compression to help site owners. 
(中间的省略....)
If you do not want a particular response from your origin to be encoded, you can disable this by setting cache-control: no-transform at your origin web server.

最后的一段说到:如果您不希望对来自您的源的特定响应进行编码,您可以通过 cache-control: no-transform 在源 Web 服务器上进行设置来禁用它。

使用示例:

header('Cache-Control: no-transform');

添加到不需要压缩页面上,cloudflare读取的时候就默认不压缩了。

相关专题
Cloudflare
Cloudflare
2023-08-07 568

Cloudflare是全球热门免费CDN服务,具备无限防御与节点加速能力,广泛用于网站安全防护。本站整理全套Cloudflare实操教程与配置方法,帮助站长合理部署防护策略,抵御网...

服务器配置教程标签