Why are mod_expires and mod_headers not working on my server?

≡放荡痞女 提交于 2019-12-11 23:33:48

问题


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:

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:

### 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.

Any ideas where I'm going wrong here?


回答1:


Your htaccess file has

<IfModule mod_expires.c>

It may be that your VPS doesn't have the mod_expires installed for apache. If that is the case then it would make sense that the expires configuration wouldn't get applied.



来源:https://stackoverflow.com/questions/21002359/why-are-mod-expires-and-mod-headers-not-working-on-my-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!