apache+tomcat 增加deflate压缩模块
来源:互联网 发布:中兴算法工程师面试题 编辑:程序博客网 时间:2024/06/06 09:06
apache2之后版本,内建一个mod_deflate模块,可以对内容压缩后再传送给客户端
这样的好处是节省网络带宽,对低带宽的客户端会加快页面显示响应
好像默认这个模块是不开启的,需要简单配置一下:
- 打开 httpd.conf 配置文件
- 确认下面两个模块是打开的:
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so - 增加如下配置:
- <VirtualHost localhost>
<Location "/">
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml - AddOutputFilter DEFLATE css
- AddOutputFilter DEFLATE js
- #AddOutputFilter 添加要压缩的类型这里压缩了: 文本 css js
- BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4/.0[678] no-gzip
BrowserMatch /bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI /.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</Location> - </VirtualHost>
- 其实tomcat本身在5.0版本以后是支持内容压缩的,它使用的是gzip的压缩格式,我们先来看 Tomcat文档中对下面两个配置的注解(红色粗体字部分)
compressableMimeType
The value is a comma separated list of MIME types for which HTTP compression may be used. The default value is
text/html,text/xml,text/plain
.compression
The Connector may use HTTP/1.1 GZIP compression in an attempt to save server bandwidth. The acceptable values for the parameter is "off" (disable compression), "on" (allow compression, which causes text data to be compressed), "force" (forces compression in all cases), or a numerical integer value (which is equivalent to "on", but specifies the minimum amount of data before the output is compressed). If the content-length is not known and compression is set to "on" or more aggressive, the output will also be compressed. If not specified, this attribute is set to "off".
这两个配置是在servere.xml中的Connector部分,第一个配置是指定Tomcat压缩哪些内容,第二个配置是指示Tomcat是否启用压缩,默认是关闭的。所以假设我们要让Tomcat在默认的8080端口上的输出内容进行压缩,我们的配置应该是:
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" compression="on"/>
然后就可以了,怎么看效果呢,用firebug看响应,会看到
Content-Encoding : gzip
的response header
推荐:http://www.port80software.com/products/httpzip/在线查看响应速度,压缩率
注:apache功能很强大 这里简单配置一下 ,还有更加详细配置
- apache+tomcat 增加deflate压缩模块
- Apache deflate模块配置
- apache的deflate模块
- apache增加mod_deflate压缩模块
- Apache deflate模块配置说明
- deflate压缩
- linux下apache安装gzip紧缩(Deflate模块)
- apache 压缩模块mod_deflate
- DEFLATE 压缩算法
- DEFLATE压缩字符串
- GZip 和 deflate压缩
- DEFLATE 压缩算法
- DEFLATE 压缩算法
- 使用deflate压缩Cookie
- apache安装deflate
- apache开启gzip deflate
- Apache模块 mod_deflate 开启压缩
- apache配置压缩节省带宽增加网速
- [重要关注] 微软在一月二十二日发行一个紧急安全补丁 (MS10-002)
- 在Myeclipse7中整合struts2+spring2.5+hibernate3.2
- 关于项目上线后的预测
- 利用libtool生成makefile 转
- Core Dump Management on the Solaris OS
- apache+tomcat 增加deflate压缩模块
- Spring 使用JdbcTemplate
- Asp.Net构架(Http请求处理流程) - Part.1
- Cache技术――OSCache(一) - [缓存技术]
- LR监控windows、linux、UNIX时常见问题及操作步骤
- Cache技术――OSCache(二) - [缓存技术]
- MSN Live Messenger 乱码解决方法
- 实矩阵相乘(C++版)
- uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI)