如何解决" Pragma:no-cache"在Debain上使用Concrete5?

时间:2015-05-13 00:42:58

标签: php linux apache caching

设置

问题

我们的网站正在标题中发送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&#39; 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和网站的安装。

非常感谢任何帮助。

干杯

2 个答案:

答案 0 :(得分:1)

更新

在PHP脚本中添加max-age:

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

其中xxxx是缓存的秒数,没有缓存为零。

如果按内容类型(MIME类型)配置

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

标头设置缓存控制&#34; max-age = 0,no-store&#34;

按内容类型(MIME类型)配置缓存:
在.htaccess ot 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优先于所有其他缓存头。

如果你没有得到&#34;内部服务器错误500&#34;

,为了排除故障你已经做得很好

在FireFox或Chrome中

  • 右键单击页面
  • 选择检查元素
  • 转到&#34;网络标签&#34;
  • 从&#34;全部&#34;更改类型到&#34; HTML&#34;
  • 点击列表中的HTML页面

您应该能够确切地看到HTTP响应标头中的内容。

<强>火狐

enter image description here

<强>铬

enter image description here

答案 1 :(得分:0)

最后得出结论,页面上的一些Concrete5块阻止了页面的缓存。

如果我们打开&#34;强制全页面缓存&#34;然后我们看到一些奇怪的行为,因为缓存冻结了功能,所以我们不得不将其关闭。

基本上,由于页面上的块功能,我们无法完全缓存网站。我们只能使用APC缓存。