php - 如何在 Debian 上使用 Concrete5 解决 "Pragma: no-cache"问题?

标签 php linux apache caching

设置


问题

我们的网站在 header 中发送 Pragma: no-cache,这会阻止一些优化工作 - 包括 CloudFlare 服务:https://www.cloudflare.com/


无效的解决方案

在研究时,我们要么不理解答案,要么它们似乎是针对特定用例的(例如我们未使用的 Oracle 或 php 框架),但我们确实尝试了以下方法:

<强>1。通过站点的 .htaccess 强制缓存:

<FilesMatch "\.(ico|jpeg|png|gif|js|css)$">
   Header unset Cache-Control
   Header unset Pragma
</FilesMatch>

<强>2。通过 Concrete5 的 header.php 文件强制缓存

    header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days)

<强>3。使用 grep

在站点的根目录中搜索 no-cache
    $ grep -r "no-cache" * .
    backup/databasebackup.php:header('Cache-Control: no-cache, must-revalidate');
    concrete/core/controllers/single_pages/login.php: header("Cache-Control: no-store, no-cache, must-revalidate");
    concrete/core/controllers/single_pages/login.php: header("Pragma: no-cache");
    concrete/js/tiny_mce/plugins/spellchecker/rpc.php:header("Cache-Control: no-store, no-cache, must-revalidate");
    concrete/js/tiny_mce/plugins/spellchecker/rpc.php: header("Pragma: no-cache");
    concrete/libraries/3rdparty/securimage/securimage.php: header('Cache-Control: no-store, no-cache, must-revalidate');
    concrete/libraries/3rdparty/securimage/securimage.php: header("Cache-Control: no-store, no-cache, must-revalidate");
    concrete/libraries/3rdparty/securimage/securimage.php: header("Pragma: no-cache");

但在查看文件/脚本后,Concrete5 正在设置 no-cache(登录、数据库备份、文本编辑器配置等),我们有点理解为什么 - 而且这些似乎是针对特定的文件,而不是整个站点,对吧?

<强>4。制作一个空白的 php 文件,请求它并检查标题

空白文件是在缓存打开的情况下提供的,因此我们怀疑 php 是罪魁祸首 - 但不知道如何找出原因,抱歉。


问题

我们如何排查和解决此问题?


技能水平

我们从事前端设计并了解有关如何设置和提供 CMS 的基础知识,但在服务器配置或缓存问题故障排除方面没有太多经验。

我们可以通过命令行访问服务器,并且几乎可以完全访问 Debian、Apache 和站点的安装。

如有任何帮助,我们将不胜感激。

干杯

最佳答案

更新

在 PHP 脚本中添加 max-age:

header("Cache-Control: max-age=xxxx");

其中 xxxx 是要缓存的秒数,零表示没有缓存。

如果按Content-Type(MIME类型)配置

header('Content-Type: text/html; charset=utf-8');

header 设置缓存控制“max-age=0, no-store”

按内容类型(MIME 类型)配置缓存:
在 .htaccess 或 httpd.conf 中

ExpiresByType text/html "access plus 30 day"
ExpiresByType text/css "access plus 30 day"
ExpiresByType text/javascript "access plus 30 day"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"

如果这些方法不起作用,您需要确保模块已加载。

您需要访问 httpd.conf

LoadModule expires_module     libexec/mod_expires.so
LoadModule headers_module     libexec/mod_headers.so

AddModule mod_expires.c
AddModule mod_headers.c
...
AddModule mod_gzip.c

请注意,加载顺序在 Apache/1.3x 中很重要,mod_gzip 必须最后加载,在所有其他模块之后。

对于 Apache/2.0:

LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so

更新结束


您应该根据 MIME 类型以及(或而不是)文件扩展名添加相同的缓存。

缓存应该是max-age。

W3C 表示 max-age 优先于所有其他缓存 header 。

如果您没有收到“内部服务器错误 500”,那么您已经做得很好了

在 FireFox 或 Chrome 中

  • 右击页面
  • 选择检查元素
  • 转到“网络”标签
  • 将类型从“全部”更改为“HTML”
  • 点击列表中的HTML页面

您应该能够准确地看到 HTTP 响应 header 中的内容。

火狐

enter image description here

Chrome

enter image description here

关于php - 如何在 Debian 上使用 Concrete5 解决 "Pragma: no-cache"问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30203788/

相关文章:

php - CMB2 可重复组显示

linux - 访问硬件寄存器中的内存指针

apache - 使用 .htaccess 重定向到新网址

c++ - 我可以在 System C(或 Plain Vanilla C++)的运行时设置数据断点吗?

apache - 强制 tomcat 使用 www.domain.com 而不是 domain.com

php - 在 Linux 中使用 PHP 的 posix_kill() 导致奇怪的行为

php - my.ini 和 mysql_connect 编码

java - 将文件保存在磁盘上

php - 在搜索数据时出现 Elasticsearch 错误请求

c - 在linux c中使用深度优先搜索遍历目录