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服務器並觀察請求報文和響應報文,如下圖所示。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM