我已经在我的vps上检查了我的plesk控制面板并安装了那些mod但是当我通过http://redbot.org/运行网站来检查发送的内容时,我得到了:
This response is negotiated, but doesn't have an appropriate Vary header.
The max-age Cache-Control directive appears more than once.
Cache-Control: no-cache, max-age=0, must-revalidate, no-transform, max-age=300
所以看起来它不起作用。
这是我编辑的.htaccess:
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
# This denies access to all yml files, since developers might include sensitive
# information in them. See the docs for work-arounds to serve some yaml files
<Files *.yml>
Order allow,deny
Deny from all
</Files>
# Define some expiry header settings.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 5 minutes"
ExpiresByType image/gif "access plus 7 day"
ExpiresByType image/png "access plus 7 day"
ExpiresByType image/jpg "access plus 7 day"
ExpiresByType image/jpeg "access plus 7 day"
ExpiresByType image/ico "access plus 7 day"
ExpiresByType text/css "access plus 7 day"
ExpiresByType text/javascript "access plus 7 day"
ExpiresByType application/x-javascript "access plus 7 day"
</IfModule>
# Append the 'Vary: Accept-Encoding' for resources that might need it.
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase '/'
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###
我只是想在我的网站上添加一些客户端缓存,我还建议为无法处理gzip的客户端添加旧的Vary:Accept-Encoding - 显然这是最好的做法。
我在这里出错的任何想法?
答案 0 :(得分:2)
你的htaccess文件有
<IfModule mod_expires.c>
可能是您的VPS没有为apache安装mod_expires。如果是这种情况,则有意义的是,expires配置将不会被应用。
答案 1 :(得分:0)
您可以以 root 用户身份登录到您的服务器并运行以下 2 行代码(根据您的服务器配置、apache 版本等可能会有所不同)
a2enmod expires
a2enmod headers
然后只需重新启动您的 Apache 服务器:
systemctl restart apache2
或
service httpd restart
以上示例适用于 Ubuntu 20.04 Server,运行 Virtualmin 作为托管解决方案。 (自己测试过)
对于其他安装,Apache 版本只需在 CentOS 7、Apache 版本 1 上搜索“a2enmod expires”