简体   繁体   English

为什么mod_expires和mod_headers不能在我的服务器上运行?

[英]Why are mod_expires and mod_headers not working on my server?

I've checked my plesk control panel on my vps and those mods are installed but when I run the site through http://redbot.org/ to check what's being sent, I get: 我已经检查了我的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

So it doesn't look like it's working. 所以它看起来不像是有效的。

Here's the .htaccess that I edited: 这是我编辑的.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 ###

I'm just trying to add a little client-side caching to my site and I was also advised to add the old Vary:Accept-Encoding for clients that can't handle gzip - apparently it's best practice to. 我只是想在我的网站上添加一些客户端缓存,我还建议为无法处理gzip的客户端添加旧的Vary:Accept-Encoding - 显然这是最好的做法。

Any ideas where I'm going wrong here? 我在这里出错的任何想法?

Your htaccess file has 你的htaccess文件有

<IfModule mod_expires.c>

It may be that your VPS doesn't have the mod_expires installed for apache. 可能是您的VPS没有为apache安装mod_expires。 If that is the case then it would make sense that the expires configuration wouldn't get applied. 如果是这种情况,则有意义的是,expires配置将不会被应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM