httpd之mod_deflate---传输压缩过程

引言: 以消耗服务器的cpu的资源为代价,在发送http报文前把数据压缩,从而达到节省流量的效果

实现如下
[root@localhost ~]# httpd -M | grep deflate           ##已加载压缩功能模块
	deflate_module (shared)
[root@localhost conf.d]# grep  deflate /etc/httpd/conf.modules.d/00-base.conf 
LoadModule deflate_module modules/mod_deflate.so

[root@localhost ~]# cp /var/log/messages /main/virtualhost/aweb/messages.txt
[root@localhost ~]# chown a+r /main/virtualhost/aweb/messages.txt
[root@localhost ~]# vim /etc/httpd/conf.d/test.conf
<virtualhost *:80>
servername www.a.com
DocumentRoot /main/virtualhost/aweb
CustomLog "logs/asite_access_log" combined
<Directory "/main/virtualhost/aweb">
    Require all granted
</Directory>
addoutputfilterbytype deflate text/plain  #压缩文件格式为plain纯文本或者html,ps:一般对于图片,MP3,MP4等压缩没啥效果
addoutputfilterbytype deflate text/html	
deflatecompressionlevel 9               ##压缩比9最高。
</virtualhost>

验证如下

[root@vm1 ~]# curl -I www.a.com/messages.txt
HTTP/1.1 200 OK
Date: Fri, 16 Apr 2021 14:31:11 GMT
Server: Apache
Last-Modified: Fri, 16 Apr 2021 14:25:34 GMT
ETag: "c1f4-5c017c0cc976a"
Accept-Ranges: bytes
Content-Length: 49652
Content-Type: text/plain; charset=UTF-8

[root@vm1 ~]# curl -I --compressed www.a.com/messages.txt
HTTP/1.1 200 OK
Date: Fri, 16 Apr 2021 14:41:02 GMT
Server: Apache
Last-Modified: Fri, 16 Apr 2021 14:25:34 GMT
ETag: "c1f4-5c017c0cc976a-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 4427              ##不压缩数据体大小为49652
Content-Type: text/plain; charset=UTF-8
很多浏览器默认开启接受压缩的文件,下图为chrome浏览器截图

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值