tomcat启用gzip压缩(包含大文件)

修改conf/server.xml文件

<Connector port="8000" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" 
           compression="on"   
           useSendfile="false"
           compressionMinSize="2048" 
           noCompressionUserAgents="gozilla, traviata"   
           compressableMimeType="text/html,text/xml,application/javascript,text/css,text/plain,image/jpeg,application/json"/>

其中:
compression=“on” #gzip开关
useSendfile=“false” #如果有大文件需要压缩一定要配置,会消耗服务器CPU资源
官方解释:(bool)Use this attribute to enable or disable sendfile capability. The default value is true. Note that the use of sendfile will disable any compression that Tomcat may otherwise have performed on the response.
compressionMinSize=“2048” #大于2048才压缩
noCompressionUserAgents=“gozilla, traviata” #不压缩的浏览器。这两个浏览器我也不知道是啥,网是所有资料都有让添加,就先加上吧。。。
compressableMimeType=“text/html,text/xml,application/javascript,text/css,text/plain,image/jpeg,application/json” #压缩文件的格式。
也可以在conf/web.xml 中查看确认

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值