HAProxy的高级配置选项-压缩功能

               HAProxy的高级配置选项-压缩功能

                                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

一.压缩功能概述

  compression algo 
    启用http协议中的压缩机制,常用算法有gzip deflate
  compression type
    要压缩的类型
  示例:     compression algo gzip deflate     compression type text
/plain text/html text/css text/xml text/javascript application/javascript

二.haproxy未配置压缩功能实战

1>.配置haproxy的配置文件

[root@node102.yinzhengjie.org.cn ~]# cat /etc/haproxy/haproxy.cfg
global
    maxconn 100000
    chroot /yinzhengjie/softwares/haproxy
    stats socket /yinzhengjie/softwares/haproxy/haproxy.sock mode 600 level admin
    user haproxy
    group haproxy
    daemon
    nbproc 2
    cpu-map 1 0
    cpu-map 2 1
    nbthread 2
    pidfile /yinzhengjie/softwares/haproxy/haproxy.pid
    log 127.0.0.1 local5 info

defaults
    option http-keep-alive
    option  forwardfor
    option redispatch
    option abortonclose
    maxconn 100000
    mode http
    timeout connect 300000ms
    timeout client  300000ms
    timeout server  300000ms

listen status_page
    bind 172.30.1.102:8888
    stats enable
    stats uri /haproxy-status
    stats auth    admin:yinzhengjie
    stats realm "Welcome to the haproxy load balancer status page of YinZhengjie"
    stats hide-version
    stats admin if TRUE
    stats refresh 5s

listen WEB_PORT_80
    bind 172.30.1.102:80
    balance roundrobin
    cookie HAPROXY-COOKIE insert indirect nocache
    server web01 172.30.1.106:80  cookie httpd-106 check inter 3000 fall 3 rise 5
    server web02 172.30.1.107:80  cookie httpd-107 check inter 3000 fall 3 rise 5
    server web03 172.30.1.108:80  cookie httpd-107 check inter 3000 fall 3 rise 5 backup
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# systemctl restart haproxy
[root@node102.yinzhengjie.org.cn ~]# 

2>.浏览器访问haproxy服务器并观察请求报文和响应报文,如下图所示。

三.haproxy配置压缩功能实战

1>.配置haproxy的配置文件

[root@node102.yinzhengjie.org.cn ~]# cat /etc/haproxy/haproxy.cfg
global
    maxconn 100000
    chroot /yinzhengjie/softwares/haproxy
    stats socket /yinzhengjie/softwares/haproxy/haproxy.sock mode 600 level admin
    user haproxy
    group haproxy
    daemon
    nbproc 2
    cpu-map 1 0
    cpu-map 2 1
    nbthread 2
    pidfile /yinzhengjie/softwares/haproxy/haproxy.pid
    log 127.0.0.1 local5 info

defaults
    option http-keep-alive
    option  forwardfor
    option redispatch
    option abortonclose
    maxconn 100000
    mode http
    timeout connect 300000ms
    timeout client  300000ms
    timeout server  300000ms

listen status_page
    bind 172.30.1.102:8888
    stats enable
    stats uri /haproxy-status
    stats auth    admin:yinzhengjie
    stats realm "Welcome to the haproxy load balancer status page of YinZhengjie"
    stats hide-version
    stats admin if TRUE
    stats refresh 5s

listen WEB_PORT_80
    bind 172.30.1.102:80
    #告诉浏览器支持的压缩算法
    compression algo gzip deflate
    #告诉浏览器支持的压缩类型
    compression type text/plain text/html text/css text/xml text/javascript application/javascript
    balance roundrobin
    cookie HAPROXY-COOKIE insert indirect nocache
    server web01 172.30.1.106:80  cookie httpd-106 check inter 3000 fall 3 rise 5
    server web02 172.30.1.107:80  cookie httpd-107 check inter 3000 fall 3 rise 5
    server web03 172.30.1.108:80  cookie httpd-107 check inter 3000 fall 3 rise 5 backup
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# systemctl restart haproxy                #别忘记重启使得配置生效。
[root@node102.yinzhengjie.org.cn ~]# 

2>.浏览器访问haproxy服务器并观察请求报文和响应报文,如下图所示。

原文地址:https://www.cnblogs.com/yinzhengjie/p/12149787.html