Setup
- Debian GNU/Linux 7.6 (wheezy) will full access to Apache and virtual host files.
- Concrete5 CMS: http://www.concrete5.org/
Debian GNU / Linux 7.6(wheezy)将完全访问Apache和虚拟主机文件。
Concrete5 CMS:http://www.concrete5.org/
Problem
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 in headers,这阻碍了许多工作的优化 - 包括CloudFlare服务:https://www.cloudflare.com/
Solutions which didn't work
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搜索站点的root用于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是罪魁祸首 - 但不知道如何隔离原因抱歉。
Question
How do we troubleshoot and fix this issue?
我们如何解决并解决此问题?
Skill level
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
2 个解决方案
#1
Update
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"
标头集缓存控制“max-age = 0,no-store”
to configure cache by Content-Type (MIME Type):
In .htaccess ot httpd.conf
按内容类型(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"
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:
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.
缓存应该是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中
- Right Click page
- Select Inspect Element
- Go to the "Network Tab"
- Change Type from "All" to "HTML"
- Click on the HTML page in the list
右键单击页面
选择Inspect Element
转到“网络标签”
将类型从“全部”更改为“HTML”
单击列表中的HTML页面
You should be able to see exactly what is in the HTTP Response Header.
您应该能够确切地看到HTTP响应标头中的内容。
FireFox
Chrome
#2
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缓存。
#1
Update
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"
标头集缓存控制“max-age = 0,no-store”
to configure cache by Content-Type (MIME Type):
In .htaccess ot httpd.conf
按内容类型(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"
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:
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.
缓存应该是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中
- Right Click page
- Select Inspect Element
- Go to the "Network Tab"
- Change Type from "All" to "HTML"
- Click on the HTML page in the list
右键单击页面
选择Inspect Element
转到“网络标签”
将类型从“全部”更改为“HTML”
单击列表中的HTML页面
You should be able to see exactly what is in the HTTP Response Header.
您应该能够确切地看到HTTP响应标头中的内容。
FireFox
Chrome
#2
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缓存。