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服务器并观察请求报文和响应报文,如下图所示。

目录
相关文章
|
应用服务中间件 nginx 数据安全/隐私保护
HAProxy的高级配置选项-配置haproxy的状态页
这篇文章详细介绍了如何配置HAProxy的状态页,包括隐藏版本信息、设置自动刷新时间、自定义访问URI、配置认证信息以及启用管理功能等,并通过实战案例展示了配置过程和效果。
499 4
HAProxy的高级配置选项-配置haproxy的状态页
|
存储 缓存 算法
zram:基于压缩的RAM块设备 【ChatGPT】
zram:基于压缩的RAM块设备 【ChatGPT】
HAProxy的高级配置选项-配置haproxy支持https协议及服务器动态上下线
文章介绍了如何配置HAProxy以支持HTTPS协议和实现服务器的动态上下线。
615 8
HAProxy的高级配置选项-配置haproxy支持https协议及服务器动态上下线
|
Kubernetes API 调度
k8s中节点无法启动Pod
【10月更文挑战第3天】
431 6
|
SQL 监控 关系型数据库
MySQL 延迟从库介绍
本文介绍了MySQL中的延迟从库功能,详细解释了其工作原理及配置方法。延迟从库允许从库在主库执行完数据变更后延迟一段时间再同步,主要用于快速恢复误操作的数据。此外,它还可用于备份、离线查询及数据合规性需求。通过合理配置,可显著提升数据库系统的稳定性和可靠性。
402 4
|
监控 Apache
HAProxy的高级配置选项-Web服务器状态监测
这篇文章介绍了HAProxy的高级配置选项,特别是如何进行Web服务器状态监测,包括基于四层传输端口监测、基于指定URI监测和基于指定URI的request请求头部内容监测三种方式,并通过实战案例展示了配置过程和效果。
298 8
HAProxy的高级配置选项-Web服务器状态监测
|
10月前
|
安全 网络协议 网络安全
解析HTTP代理服务器不稳定致使掉线的关键原因
随着数字化发展,网络安全和隐私保护成为核心需求。HTTP代理服务器掉线原因主要包括:1. 网络问题,如本地网络不稳定、路由复杂;2. 服务器质量差、IP资源不稳定;3. 用户配置错误、超时或请求频率异常;4. IP失效或协议不兼容。这些问题会影响连接稳定性。
393 8
|
缓存 监控 API
抖音抖店 API 请求获取宝贝详情数据的调用频率限制如何调整?
抖音抖店API请求获取宝贝详情数据的调用频率受限,需遵循平台规则。开发者可通过提升账号等级、申请更高配额、优化业务逻辑(如缓存数据、异步处理、批量请求)及监控调整等方式来应对。
|
运维 网络安全 Docker
JumpServer——使用Docker快速搭建
JumpServer——使用Docker快速搭建
383 1
JumpServer——使用Docker快速搭建
|
Ubuntu 应用服务中间件 Linux
Linux Centos7 ubuntu 安装nginx,脚本一键安装nginx
Linux Centos7 ubuntu 安装nginx,脚本一键安装nginx
326 2
下一篇
开通oss服务