[英]How to troubleshoot “Pragma: no-cache” with Concrete5 on Debain?
Our website is sending Pragma: no-cache
in headers which is stopping a number of optimisations from working - including the CloudFlare service: https://www.cloudflare.com/ 我们的网站正在发送Pragma: no-cache
标头中Pragma: no-cache
,这阻止了许多优化工作-包括CloudFlare服务: https : //www.cloudflare.com/
When researching, we either didn't understand the answers or they seemed to be for specific use cases (like Oracle or php frameworks we're not using) but we did try the following: 在研究时,我们要么不理解答案,要么似乎是针对特定的用例(例如我们未使用的Oracle或php框架),但是我们尝试了以下方法:
1. Force caching via the site's .htaccess
: 1.通过站点的.htaccess
强制缓存:
<FilesMatch "\.(ico|jpeg|png|gif|js|css)$">
Header unset Cache-Control
Header unset Pragma
</FilesMatch>
2. Force caching via Concrete5's header.php file 2.通过Concrete5的header.php文件强制缓存
header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days)
3. Search site's root for no-cache
using grep 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");
But after looking at the files/scripts Concrete5 is setting no-cache
on (login, database backups, text editor configs etc), we kind of understand why - plus these seem to be for specific files, not the entire site right? 但是在查看了文件/脚本后,Concrete5设置了no-cache
(登录,数据库备份,文本编辑器配置等)后,我们有点理解为什么-加上这些似乎是针对特定文件的,而不是整个网站的权利?
4. Make a blank php file, request it and check the header 4.制作一个空白的php文件,请求并检查标题
The blank file was served with caching on so we suspect that php is the culprit - but have no idea how to isolate the cause sorry. 空白文件已缓存,因此我们怀疑php是罪魁祸首-但不知道如何找出原因对不起。
How do we troubleshoot and fix this issue? 我们如何解决和解决此问题?
We do front-end design and understand the basics on how to setup and serve a CMS but don't have much experience with server configuration or troubleshooting cache issues. 我们进行前端设计,并了解有关如何设置和服务CMS的基础知识,但对服务器配置或缓存问题的故障处理经验不足。
We have command line access to the server and pretty much have full access to Debian, Apache, and the site's install. 我们可以通过命令行访问服务器,并且几乎可以完全访问Debian,Apache和站点的安装。
Any help would be much appreciated. 任何帮助将非常感激。
Cheers 干杯
Ben 本
To add max-age in a PHP script: 要在PHP脚本中添加max-age:
header("Cache-Control: max-age=xxxx");
Where xxxx
is the number of seconds to cache, zero for no cache. 其中xxxx
是要缓存的秒数,如果没有缓存则为零。
OR 要么
If you configure by Content-Type (MIME Type) 如果按内容类型(MIME类型)进行配置
header('Content-Type: text/html; charset=utf-8');
Header Set Cache-Control "max-age=0, no-store" 标头集缓存控制“最大年龄= 0,无存储”
to configure cache by Content-Type (MIME Type): 通过内容类型(MIME类型)配置缓存:
In .htaccess ot httpd.conf 在.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"
If these methods are not working you need to majke sure the modules are loaded. 如果这些方法不起作用,则需要确保已加载模块。
You need access to httpd.conf 您需要访问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
Note that the load order is important in Apache/1.3x, mod_gzip must load last, after all other modules. 请注意,加载顺序在Apache / 1.3x中很重要,mod_gzip必须在所有其他模块之后最后加载。
For Apache/2.0: 对于Apache / 2.0:
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so
end of Update 更新结束
You should add the same cache based on MIME Type as well as (or rather than) file extension. 您应该基于MIME类型以及(或而不是)文件扩展名添加相同的缓存。
The cache should be max-age. 缓存应为最大容量。
The W3C says max-age takes precedence over all other cache headers. W3C说max-age优先于所有其他缓存头。
To troubleshoot you are doing well already if you are not getting "Internal Server Error 500" 要进行故障排除,如果您没有遇到“内部服务器错误500”,那就已经做好了。
In FireFox or Chrome 在FireFox或Chrome中
You should be able to see exactly what is in the HTTP Response Header. 您应该能够确切看到HTTP响应标题中的内容。
FireFox 火狐
Chrome 铬
Finally got to the bottom of this, some of the Concrete5 Blocks on pages are stopping the pages from being cached. 归根到底,页面上的一些Concrete5块阻止了页面的缓存。
If we turn on "Force full page caching" then we see some weird behaviour because the functionality is frozen by the cache, so we've had to turn it off. 如果启用“强制全页缓存”,则会看到一些奇怪的行为,因为该功能已被缓存冻结,因此必须将其关闭。
Essentially, we can't cache the site fully because of the functionality in blocks on the page. 本质上,由于页面上的块中的功能,我们无法完全缓存网站。 We can only use APC caching. 我们只能使用APC缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.