load-balancing - HaProxy:如何记录响应正文
问题描述
HaProxy:如何记录响应正文
我能够捕获请求正文,但我无法记录响应正文
我尝试了多个选项,但无法捕获响应正文。
- 有没有办法记录响应正文?
- 另外,它只能用于 POST 请求吗?
HaProxy.cfg
global
log 127.0.0.1 local0
debug
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
option http-keep-alive
timeout http-keep-alive 5m
timeout http-request 5s
timeout connect 10s
timeout client 300s
timeout server 300s
timeout check 2s
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
balance roundrobin
option httpchk
frontend LB
bind *:80
option httpclose
option forwardfor
option http-buffer-request
declare capture request len 400000
#declare capture response len 400000
#http-response capture res.header id 0
http-request capture req.body id 0
log-format "%ci:%cp-[%t]-%ft-%b/%s-[%Tw/%Tc/%Tt]-%B-%ts-%ac/%fc/%bc/%sc/%rc-%sq/%bq body:%[capture.req.hdr(0)]/ Response: %[capture.res(0)]"
monitor-uri /
#default_backend LB
# BEGIN YPS ACLs
acl is_yps path_beg /ems
use_backend LB if is_yps
# END YPS ACLs
backend LB
option httpchk GET /ems/login.html
server 10.164.29.225 10.164.30.50:8080 maxconn 300 check
server 10.164.27.31 10.164.30.50:8080 maxconn 300 check backup
解决方案
您可以通过在 cfg 文件中添加以下内容来记录正文
- 在前端需要添加以下两行
声明捕获请求行 400000
HTTP-request 捕获 req.body id 0
- 由于默认日志行长度为 1024,因此要记录完整请求需要指定最大长度
日志 127.0.0.1 len 65335 local0
无需更改日志格式,使用默认的日志格式
推荐阅读
- android - 是否可以通过仅在 Android 项目中使用最高质量的资源来减小应用程序大小?
- charts - Google Chart BarChart onmouseover
- javascript - 通过firebase更新反应本机复选框的值
- java - 控制器导致浏览器在错误的路径中查找 CSS
- macos - Applescript将目录列表添加到查找器侧边栏收藏夹
- reactjs - 未定义的 mapStateToProps React Redux
- sql - SQL,将主查询的结果转化为子查询
- azure-iot-edge - 模块双胞胎空着回来
- java - 未找到 JPA 实体
- installation - 预置 16.04 的权限问题