引言: 以消耗服务器的cpu的资源为代价,在发送http报文前把数据压缩,从而达到节省流量的效果
实现如下
[root@localhost ~]
deflate_module (shared)
[root@localhost conf.d]
LoadModule deflate_module modules/mod_deflate.so
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
<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
addoutputfilterbytype deflate text/html
deflatecompressionlevel 9
</virtualhost>
验证如下
[root@vm1 ~]
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 ~]
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
Content-Type: text/plain; charset=UTF-8
很多浏览器默认开启接受压缩的文件,下图为chrome浏览器截图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5551eb64df50e27bfccc09310ef1a32a.png)