【问题标题】:Magento and Apache - Cache settings seem to be ignoredMagento 和 Apache - 缓存设置似乎被忽略了
【发布时间】:2012-08-24 02:24:14
【问题描述】:

我正在运行一个 Magento 实例,并且正在尝试为不会经常更改的内容设置缓存规则。我将我想要的规则添加到位于 Magento 根文件夹中的 .htaccess 文件(规则在帖子的底部),但它们似乎被忽略了。当我检查 http 标头时,我看到的是:

Pragma: no-cache, no-cache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, private, no-cache, no-store, proxy-revalidate, no-transform

显然,我在这里做错了。有什么我应该检查的,看看谁在强制执行“无缓存”策略,在哪里?提前感谢您的回答。

添加到 .htaccess 文件的规则

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0

# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
    ExpiresDefault A29030400
    Header append Cache-Control "public"
</FilesMatch>

# Set up caching on media files for 2 weeks
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
    ExpiresDefault A1209600
    Header append Cache-Control "public"
</FilesMatch>

# Set up 1 week caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
    ExpiresDefault A604800
    Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
    ExpiresActive Off
    Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    Header set Pragma "no-cache"
</FilesMatch>

【问题讨论】:

    标签: .htaccess magento caching


    【解决方案1】:

    你知道 /media 中有一个 htaccess 吗? (换脸...)

    如果您这样做,那么您可能需要考虑将“静态”内容放在单独的子域中,即无 cookie。

    在 Magento 后台进入 system->config->general->web 并输入http://static.yourdomain.com/

    现在您可以将 .htaccess 指令移动到原始 httpd.conf 文件中(这在理论上更快)并删除/停放 .htaccess 文件。

    现在将 cookie 域(在“会话 Cookie 管理”中)设置为 www.yourdomain.com - 现在 static.yourdomain.com 上不会有任何 cookie,因此 Web 服务器应该更快捷。如果这些图像没有通过,那么您可能需要在您的 DNS 'A' 记录上设置一个通配符,以便任何非 www 地址都通过同一个框。

    您现在可以微调 /media 中的 .htaccess 文件,并将这些指令放在 static.yourdomain.com.conf 中

    【讨论】:

    • 我不知道 Media 中的 .htaccess,我必须检查一下。其他的建议也不错,但我已经知道了,现在不能应用,因为这是临时托管,我无权访问 httpd.conf。这就是为什么我尝试仅使用 .htaccess 尽可能多地改善这种情况。
    • 我是否在 /media 中的 htaccess 框中打勾?
    猜你喜欢
    • 2012-01-13
    • 2021-10-28
    • 2016-09-30
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2012-03-08
    • 2015-12-11
    相关资源
    最近更新 更多