日期:2014-05-16  浏览次数:20895 次

apache配置,给服务器添加gzip压缩支持
headers_module
> cd standard (有的在modules/metadata目录下)
> /user/local/apache/bin/apxs -i -a -c mod_headers.c
> /user/local/apache/bin/apxs -i -a -c mod_deflate.c
mod_deflate

启用gzip可以大大减少传输的数据大小,从而使页面打开更快

#下面是我添加的gzip的部分 
<Location "/">
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images and other
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Header append Vary User-Agent env=!dont-vary

<LimitExcept GET POST HEAD>
Order Allow,Deny
Deny from all
</LimitExcept>

</Location>



如果出现如下错误
Cannot load /usr/local/apache/modules/mod_deflate.so into server: /usr/local/apache/modules/mod_deflate.so: undefined symbol: inflateEnd

解决办法:

办法1.需要在 LoadModule deflate_module  modules/mod_deflate.so 的前面加载zlib.so
如32操作系统增加以下内容:
LoadFile /usr/lib/libz.so
LoadModule deflate_module     modules/mod_deflate.so
如64操作系统增加以下内容:
LoadFile /usr/lib64/libz.so
LoadModule deflate_module     modules/mod_deflate.so