Magento和Apache-缓存设置似乎被忽略 [英] Magento and Apache - Cache settings seem to be ignored

查看:97
本文介绍了Magento和Apache-缓存设置似乎被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running an instance of Magento and I'm trying to set the caching rules for the content that is not going to change often. I added the rules I wanted to the .htaccess file (rules are at the bottom of the post) which is located in Magento root folder, but they seem to be ignored. When I check the http headers, this is what I see:

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

很显然,我在这里做错了.有什么我应该检查的,看看谁在强制执行不缓存"策略,在哪里?预先感谢您的回答.

Obviously, I'm doing something wrong here. Is there anything I should check to see who is forcing a "no-cache" policy, and where? Thanks in advance for the answers.

规则已添加到.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>

推荐答案

您是否知道/media中存在htaccess? (面部植物...)

You did know there is a htaccess in /media? (Faceplant...)

如果您这样做,则可能需要考虑将静态"内容放在一个单独的子域中,该子域不包含Cookie.

If you are doing this then you may want to consider putting the 'static' content on a separate sub domain, one that is cookie free.

在Magento的后端中,转到系统"->配置"->常规"->"Web",然后输入 http://static. yourdomain.com/

In the backend of Magento go to system->config->general->web and enter http://static.yourdomain.com/

现在,您可以将.htaccess指令移动到原始的httpd.conf文件中(从概念上讲这是更快的),然后删除/存放.htaccess文件.

Now you can move the .htaccess directives into your original httpd.conf file (this is notionally quicker) and remove/park the .htaccess file.

现在将cookie域(在会话cookie管理"中)设置为www.yourdomain.com-现在static.yourdomain.com上将不再有任何cookie,因此Web服务器应该更灵活.如果这些图像没有通过,则可能需要在DNS'A'记录上设置通配符,以便所有非www地址都通过同一框.

Now set the cookie domain (in 'Session Cookie Management') to www.yourdomain.com - now there won't be any cookies on static.yourdomain.com so the web server should be snappier. If those images are not coming through then you may need to setup a wildcard on your DNS 'A' record so that any non-www address goes through to the same box.

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

You can now fine-tune the .htaccess file in /media and put those directives in the static.yourdomain.com.conf

这篇关于Magento和Apache-缓存设置似乎被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆