大网数据广告活动
服务器运维问答

Logging entire POST body with HAProxy?

· 52CE 我爱测

I'm trying to track down some problems with the way a javascript client is interacting with an application server and would like to see the entire http payload (headers, body, and everything) that is being passed back and forth. …

问题原文

原帖链接 · Peter Groves · CC BY-SA 3.0

I'm trying to track down some problems with the way a javascript client is interacting with an application server and would like to see the entire http payload (headers, body, and everything) that is being passed back and forth.

It so happens that there is already an haproxy server in front of the application server, so I was hoping to be able to use haproxy to provide the relevant logs. Obviously this would be bad to turn on in production, but I have a clone of the entire environment that can be isolated while I do this debugging.

Is there a way to get haproxy to log the entire http payload for POST requests going to a particular backend server?

社区高分解答

原帖链接 · hack_on · CC BY-SA 3.0

Apparently since version 1.6.0 (October 2015) you can now. There is a new directive:

option http-buffer-request

That you include in the front-end or back-end to give HAProxy access to the body. And you use req.body to access it. Here is a summary of the config I used:

global
        log     127.0.0.1 local0
        debug
        maxconn 2048
        ulimit-n 8012
#        ...

defaults
    mode http
    option httplog
    log-format frontend:%f/%H/%fi:%fp\ GMT:%T\  body:%[capture.req.hdr(0)]\ request:%r
    option dontlognull
#   ...

frontend www-http
   log global
   option http-buffer-request
# id=0 to store body for logging
   declare capture request len 40000
   bind 7.7.7.7:8007 
   http-request capture req.body id 0

   default_backend www-backend

backend www-backend
    mode http
    option forwardfor
#   ...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-07-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。