gzip压缩需要 deflate_module和headers_module的支持;系统默认就是开启的;
还需要开启 LoadModule deflate_module modules/mod_deflate.so
否则报错
AH00526: Syntax error on line 521 of /alidata/server/httpd/conf/httpd.conf:
Unknown filter provider DEFLATE
http.conf 里添加下面的配置


     AddOutputFilterByType DEFLATE text/plain
     AddOutputFilterByType DEFLATE text/css
     AddOutputFilterByType DEFLATE application/xml
     AddOutputFilterByType DEFLATE application/rss+xml
     AddOutputFilterByType DEFLATE application/atom_xml
     AddOutputFilterByType DEFLATE application/x-javascript
     AddOutputFilterByType DEFLATE application/x-httpd-php
     AddOutputFilterByType DEFLATE text/html

重启apache
http://tool.chinaz.com/Gzips测试一下
看网上还有一种办法适用于不能随便重启apache的生产环境


 
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
 
    # Insert filter on all content
    ###SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    DeflateCompressionLevel 9
    SetOutputFilter DEFLATE
 
    # Netscape 4.x has some problems...
    #BrowserMatch ^Mozilla/4 gzip-only-text/html
 
    # Netscape 4.06-4.08 have some more problems
    #BrowserMatch ^Mozilla/4\.0[678] no-gzip
 
    # MSIE masquerades as Netscape, but it is fine
    #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 
    # Don't compress images
    #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
 
    # Make sure proxies don't deliver the wrong content
    #Header append Vary User-Agent env=!dont-vary
 

标签: 网页压缩

仅有一条评论

  1. Wind

    :!: :!: :!: :!: :!: :!:

评论已关闭