haproxy 压缩功能
对响应给客户端的报文进行压缩,以节省网络带宽,但是会占用部分CPU性能
配置选项
-
compression algo #启用http协议中的压缩机制,常用算法有gzip deflate
- dentity #调试使用的压缩方式
- gzip #常用的压缩方式,与各浏览器兼容较好
- deflate #有些浏览器不支持
- raw-deflate #新出的压缩方式
-
compression type #要压缩的文件类型
配置示例
listen web_host
bind 192.168.1.101:80
mode http
balance roundrobin
log global
option httplog
#capture request header X-Forwarded-For len 15
#capture request header User-Agent len 512
compression algo gzip deflate
compression type compression type text/plain text/html text/css text/xml text/javascript application/javascript
cookie SERVER-COOKIE insert indirect nocache
server web1 192.168.1.103:80 cookie web1 check inter 3000 fall 3 rise 5
server web2 192.168.1.104:80 cookie web2 check inter 3000 fall 3 rise 5
验证:
用户浏览器支持的算法为gzip ,defalte ;haproxy 也支持这些算法, 最终它们选择gizp 作为传输的压缩方式