Apahce使用mod_deflate压缩模块,客户端(如浏览器)每次都会去服务器取数据(ps:Expires没有过期等情况下),即http请求头的状态码永远为200,而不会访回 304 Not Modified。 304 Not Modified?
问题F5刷新,状态永远200,如下图: 这是Apahce本身的一个bug。Apache同时使用gzip压缩和缓存,etag名字会自动变成“******-gzip”,当存在gzip时就会出现问题。 解决方法如果使用了《OneinStack》和《lnmp一键安装包》(ps:最新下载的已解决这个问题)选择安装了lamp模式,将会自动打开的压缩功能,需要通过如下方法解决此问题: 将文件/usr/local/apache/conf/httpd.conf最后几行将:
ServerTokens ProductOnly
ServerSignature Off
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
DeflateCompressionLevel 6
SetOutputFilter DEFLATE
Include conf/vhost/*.conf
替换为:
<IfModule mod_headers.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
<FilesMatch "\.(js|css|html|htm|png|jpg|swf|pdf|shtml|xml|flv|gif|ico|jpeg)$">
RequestHeader edit "If-None-Match" "^(.*)-gzip(.*)$" "$1$2"
Header edit "ETag" "^(.*)-gzip(.*)$" "$1$2"
</FilesMatch>
DeflateCompressionLevel 6
SetOutputFilter DEFLATE
</IfModule>
ServerTokens ProductOnly
ServerSignature Off
Include conf/vhost/*.conf
重启apache:
测试F5刷新: 转载请保留固定链接: https://linuxeye.com/Linux/2871.html |