为什么mod_expires和mod_headers在我的服务器上不起作用? [英] Why are mod_expires and mod_headers not working on my server?

查看:150
本文介绍了为什么mod_expires和mod_headers在我的服务器上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在vps上检查了plesk控制面板,并且安装了这些mod,但是当我通过 http://来运行网站时redbot.org/检查正在发送的内容,我得到:

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.

这是我编辑的.htaccess文件:

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

我只是想在网站上添加一些客户端缓存,还建议我为无法处理gzip的客户端添加旧的Vary:Accept-Encoding-显然,这是最佳做法.

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?

推荐答案

您的htaccess文件具有

Your htaccess file has

<IfModule mod_expires.c>

可能是您的VPS没有为Apache安装mod_expires.如果是这种情况,那么就不会应用过期配置是有道理的.

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.

这篇关于为什么mod_expires和mod_headers在我的服务器上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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