1.打开Firefox浏览器的开发工具
#一般针对压缩的为html、css、js等,不需要压缩的是图片、视频
2.配置httpd的gzip压缩页面
#在ErrorLog "logs/error_log"的后面添加配置
vi /etc/httpd/conf/httpd.conf
ErrorLog "logs/error_log"
<ifmodule mod_deflate.c>
SetOutputFilter DEFLATE
DeflateCompressionLevel 9
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
</ifmodule>
#检查配置文件是否错误
httpd -t
#配置后要重启httpd服务
systemctl restart httpd
参数名称 | 参数说明 |
---|---|
SetOutputFilter DEFLATE | 启动gzip压缩功能 |
DeflateCompressionLevel | 压缩级别,1-9,9为最高 |
DeflateFilterNote Input instream | 声明输入流的byte数量 |
DeflateFilterNote Output outstream | 声明输出流的byte数量 |
DeflateFilterNote Ratio ratio | 声明压缩的百分比 |
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript | 指定压缩MIME类型文件 |
3.打开firefox浏览器的开发者工具,查看是否开启gzip压缩
#查看响应头是否有Content-Encoding: gzip,否则开启失败
#查看传输文件的大小是否有压缩