【问题标题】:prevent Apache from serving pages with 304 status code阻止 Apache 提供 304 状态码的页面
【发布时间】:2015-06-22 22:08:52
【问题描述】:

我有一个服务器、LAMP、设置和一个 CakePHP 应用程序。当我通过任何网络浏览器请求网页时,它总是以 304 状态回复,即使在我更改页面后也提供旧页面。似乎服务器将任何以前访问过的页面保存在缓存中,并将其提供给之后请求它的任何人。例如:用户“X”登录该系统并访问“主页”页面并注销。当另一个用户“Y”登录系统时,他将看到“X”的“家”,而他应该访问他的主页并显示他的名字。相反,他认为它是 X 之前访问过的。当我完全删除一个资源时,比如“主页”页面,它仍然可以访问。我已经检查过,页面提供了 304 not modified 状态码;但是我未能在我的 apache 设置中修改此行为;我是新手,我没有解决方案。任何帮助将不胜感激。

【问题讨论】:

    标签: apache cakephp lamp http-status-code-304


    【解决方案1】:

    如果其他人有同样的问题,我会回答我自己的问题。我找到了这种行为的潜在原因。我的 apache 设置很好,但我的局域网有一个 Apache Traffic Server,它会缓存一些资源,默认情况下会缓存图像和 css 文件之类的东西。如果对文件进行了修改,建议将其重命名,以便不提供旧文件。对于网页,我通过添加以下内容来强制它们不缓存:

    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="cache-control" content="no-store" />
    <meta http-equiv="cache-control" content="must-revalidate" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    

    在使用 cakePHP 时,我还在 AppController 文件 (asked here) 的 beforeFilter 方法中添加了以下几行:

    function beforeFilter() {
    
        /**
         * https://stackoverflow.com/questions/27804628/cakephp-caching-issue-when-redirecting-back-to-same-page
         */
    
        header('Cache-Control: no-cache, no-store, must-revalidate');
        header('Pragma: no-cache');
        header('Expires: 0');
    
    }
    

    我希望它对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-10-25
      • 2020-08-14
      • 2021-01-17
      • 2022-07-28
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 2017-03-27
      • 2018-03-23
      相关资源
      最近更新 更多