apache和tomcat开启GZIP功能

原创
2013/01/28 18:19
阅读数 163

1. apache2.2 和 tomcat6

2. tomcat6的server.xml文件配置:

     < Connector port ="80" maxHttpHeaderSize ="8192" 
           maxThreads ="150" minSpareThreads ="25" maxSpareThreads ="75" 
           enableLookups ="false" redirectPort ="8443" acceptCount ="100" 
           connectionTimeout ="20000" disableUploadTimeout ="true" compression="on"   compressableMimeType="text/html,text/xml,text/css,text/javascript,image/gif,image/jpeg,image/png,image/img,application/x-javascript,text/plain,application/json" URIEncoding ="utf-8" /> 

1) compression="on" 打开压缩功能 
2) compressionMinSize="2048" 启用压缩的输出内容大小,这里面默认为2KB 
3) noCompressionUserAgents="gozilla, traviata" 对于以下的浏览器,不启用压缩 
4) compressableMimeType="text/html,text/xml" 压缩类型 

3. apache2.2的httpd.conf配置:

1)针对Apache2.0之前的版本,它原本是不支持的,不过可以通过添加第三方的module_gzip模块来启用

2)针对Apache2.0及之后的版本,Apache 提供支持, 不过不叫gzip,而叫mod_deflate

  开启三个模块:

在Apache的配置文件中找到下面两行,将注释#去掉,重启。
LoadModule deflate_module modules/mod_deflate.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so

增加:

<IfModule expires_module>
ExpiresActive On
ExpiresDefault "access plus 12 month"
ExpiresByType text/html "access plus 12 months"
ExpiresByType text/css "access plus 12 months"
ExpiresByType image/gif "access plus 12 months"
ExpiresByType image/jpeg "access plus 12 months"
ExpiresByType image/jpg "access plus 12 months"
ExpiresByType image/png "access plus 12 months"
ExpiresByType image/img "access plus 12 months"
EXpiresByType application/x-shockwave-flash "access plus 12 months"
EXpiresByType application/x-javascript      "access plus 12 months"
ExpiresByType video/x-flv "access plus 12 months"
</IfModule>

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
</IfModule>
或:

<IfModule deflate_module>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
</IfModule>

 

  


展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部