Apache服务器压缩和利用浏览缓存问题


Apache server compression and leverage browse caching problems

我的apache web服务器管理员,声称,服务器支持deflate gzip压缩,因此,显示环境变量HTTP_ACCEPT_ENCODING gzip,deflate给我。

我知道有两种压缩方法。方法一是在PHP级别,使用ob_start('ob_gzhandler');方法二是在服务器级别,使用.htaccess,其中包含一些命令,如

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

<FilesMatch "''.(js|css|html|htm|php|xml)$">

SetOutputFilter DEFLATE

</FilesMatch>

我用一些工具检查两种压缩方法,如页面速度

第一种方法对我有效,但第二种方法不起作用。我喜欢使用服务器端压缩的方法,我发现很多人在网上有像我一样的问题。服务器管理员只声明everything is ok from his point of view and gzip/deflate is active

我有其他问题与leverage browse caching谷歌推荐站长使用它。

就像压缩一样,.htaccess文件也有标准代码,比如这个

<IfModule mod_expires.c>

ExpiresActive On

ExpiresByType image/jpg "access 1 year"

ExpiresByType image/jpeg "access 1 year"

ExpiresByType image/gif "access 1 year"

ExpiresByType image/png "access 1 year"

ExpiresByType text/css "access 1 month"

ExpiresByType application/pdf "access 1 month"

ExpiresByType text/x-javascript "access 1 month"

ExpiresByType application/x-shockwave-flash "access 1 month"

ExpiresByType image/x-icon "access 1 year"

ExpiresDefault "access 2 days"

</IfModule>

不幸的是,

不像压缩那样工作。我们的apache服务器版本是2.2.20.

我不知道如何向服务器管理员证明,服务器安装有问题。

可能是这个版本的apache的一个bug。我真的很困惑,尤其是当我知道世界上还有一些人和我有着完全相同的问题,却没有回应的时候。

一个可能的解释:Apache服务器可能被配置为不允许覆盖(即,在本地。htaccess文件中的更改)。查看Apache AllowOverride文档页面,看看这是否可能是这里的问题。

在我的情况下,我的共享网络主机没有安装mod_gzip或mod_deflate,所以我使用相同的PHP方法你提到的,它工作得很好。

我建议使用Curl作为测试压缩和过期设置的快速方法。(这也是一种与服务器管理员共享结果的简单方法。)

例如,要检查压缩,包括"——compress"选项,并查找响应头"Content-Encoding: gzip":
$ curl --head --compress http://cdn.sstatic.net/stackoverflow/all.css
HTTP/1.1 200 OK
Server: nginx/0.8.36
Date: Wed, 28 Dec 2011 03:15:22 GMT
Content-Type: text/css
Connection: keep-alive
Cache-Control: max-age=604800
Last-Modified: Wed, 28 Dec 2011 00:54:40 GMT
ETag: "0c85c47fbc4cc1:0"
X-Cache: HIT
Content-Encoding: gzip

你也可以检查工作Expires头:

$ curl --head http://l.yimg.com/a/i/us/sp/v/ncaaf/teams/1/80x60/sss3.gif
HTTP/1.1 200 OK
Date: Thu, 22 Dec 2011 01:34:59 GMT
Cache-Control: max-age=315360000
Expires: Sun, 19 Dec 2021 01:34:59 GMT
Last-Modified: Fri, 11 Dec 2009 16:54:28 GMT
Accept-Ranges: bytes
Content-Length: 3059
Content-Type: image/gif
Age: 524606
Connection: keep-alive
Server: YTS/1.20.9