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

发布于 2024-12-23 03:50:07 字数 1656 浏览 1 评论 0原文

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

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

第一种方法适合我,但第二种方法确实有效不工作。 我想使用服务器端压缩方法,我发现网上很多人都像我一样有问题。 服务器管理员只是声称从他的角度来看一切都很好,并且 gzip/deflate 处于活动状态

我在利用浏览缓存方面还有其他问题,谷歌建议网络管理员使用它。

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

ExpiresActive On

ExpiresByType image/jpg“访问 1 年”

ExpiresByType image/jpeg“访问 1 年”

ExpiresByType image/gif“访问 1年”

ExpiresByType image/png“访问 1 年”

ExpiresByType text/css“访问 1 个月”

ExpiresByType application/pdf“访问 1 个月”

ExpiresByType text/x-javascript“访问 1 个月”

ExpiresByType application/x-shockwave-flash“访问 1 个月”

ExpiresByType image/x-icon "access 1year"

ExpiresDefault "access 2 days"

不幸的是,它不起作用压缩。 我们的apache服务器版本是2.2.20。

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

也许这是这个版本的apache的一个bug。 我真的很困惑,特别是当我了解到世界上有一些人和我有完全相同的问题并且没有回复时。

My apache web server admin, claims that,the server supports deflate gzip compression and for reason, shows environment variable HTTP_ACCEPT_ENCODING gzip,deflate to me.

I know there is two method for compression. method one, is in PHP level, using ob_start('ob_gzhandler') and second method is in server level, using .htaccess with some commands in it, like this one

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

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

SetOutputFilter DEFLATE

</FilesMatch>

I check both compression method with some tools like page speed

First method works for me properly, but second method does not work.
I'd like to use server side compression method, and i found many people in the net have problem like me.
Server admin just claims everything is ok from his point of view and gzip/deflate is active

I have other problem with leverage browse caching which google recommend web masters to using it.

just like compression, there are standard codes for .htaccess file, like this one

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

unfortunately, it does not work like compression.
our apache server version is 2.2.20.

I don't know how prove to server admin, which there is something wrong with server installation.

perhaps it's a bug of this version of apache.
i am really confuse, specially when i understand there are some people in the world, which have exactly same problems like me and there is no reply.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春如此纠结 2024-12-30 03:50:07

一种可能的解释是: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

One possible explanation: the Apache server may be configured to not allow overrides (i.e., changes in a local .htaccess file). See the Apache AllowOverride docs page to see if that may be the issue here.

In my case my shared web host doesn't have mod_gzip or mod_deflate installed, so I use the same PHP method you mentioned and it works pretty well.

I recommend using Curl as a quick method to test both compression and expires settings. (It's also an easy way to share results with your server admin.)

For example, to check for compression, include the "--compress" option, and look for a response header "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

You can also check for the working Expires header:

$ 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文