【问题标题】:Apache server compression and leverage browse caching problemsApache 服务器压缩和利用浏览缓存问题
【发布时间】:2012-01-28 11:25:15
【问题描述】:

我的 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>

我使用page speed等工具检查这两种压缩方法

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

我对@9​​87654330@ 有其他问题,谷歌推荐网站管理员使用它。

就像压缩一样,.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的一个错误。 我真的很困惑,特别是当我了解到世界上有一些人和我有完全相同的问题并且没有回复时。

【问题讨论】:

    标签: php linux apache caching compression


    【解决方案1】:

    一种可能的解释:Apache 服务器可能被配置为不允许覆盖(即,更改本地 .htaccess 文件)。请参阅Apache AllowOverride docs page,看看这是否可能是这里的问题。

    在我的情况下,我的共享网络主机没有安装 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

    【讨论】:

    • 谢谢..非常好...我不知道 curl!...我下载了它,它非常适合您的示例,但不幸的是,当我像 curl --compress http://www.mysite.com 一样使用它时,它会返回 @ 987654327@ 错误!....我为我的新错误创建了新问题。请看这个link...但是没有有用的回复...这些问题到底是什么?!...谁是救世主?!...你可以布莱恩...我知道你是那个人布赖恩。
    猜你喜欢
    • 2017-08-23
    • 2014-07-08
    • 2020-09-10
    • 1970-01-01
    • 2015-09-06
    • 2014-02-07
    • 2017-06-23
    • 2013-09-26
    • 1970-01-01
    相关资源
    最近更新 更多