I want to record HTTP Post’s request body to the log, but I tried many methods to achieve it. Where is my configuration problem? I hope to help me thank me very much.
I use the Windows version Caddy 2.9.1 version
My Caddyfile file content
{
debug
}
test.wanvb.com {
log {
output file access.log
format json
}
handle {
log_append area "dynamic"
log_append postbody {http.request.body}
log_append method {http.request.method}
reverse_proxy http://127.0.0.1:5805
}
tls {
dns dnspod 5511***,ad3b981490f4d85d******
on_demand
}
}
The real log record content is
{"level":"info","ts":1738420546.9797857,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"117.189.107.50","remote_port":"6849","client_ip":"117.189.107.50","proto":"HTTP/1.1","method":"POST","host":"test.wanvb.com","uri":"/UKEYA.php","headers":{"Accept":["*/*"],"Sec-Fetch-Site":["cross-site"],"Content-Length":["52"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF XWEB/8391"],"Sec-Fetch-Mode":["cors"],"Sec-Fetch-Dest":["empty"],"Referer":["https://test.wanvb.com/UKEYA.php"],"Xweb_xhr":["1"],"Cache-Control":["no-cache"],"Content-Type":["application/x-www-form-urlencoded"],"Cookie":["REDACTED"],"Accept-Language":["zh-cn"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"","server_name":"test.wanvb.com"}},"bytes_read":52,"user_id":"","duration":0.0350536,"size":6,"status":200,"resp_headers":{"Content-Type":["text/html; charset=utf-8"],"X-Powered-By":["PHP/8.2.0"],"Server":["Caddy","nginx"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Date":["Sat, 01 Feb 2025 14:35:46 GMT"]},"method":"POST","postbody":"","area":"dynamic"}
{"level":"info","ts":1738420563.9426904,"logger":"http.log.access.log0","msg":"handled request","request":{"remote_ip":"117.189.107.50","remote_port":"6874","client_ip":"117.189.107.50","proto":"HTTP/1.1","method":"POST","host":"test.wanvb.com","uri":"/UKEYA.php","headers":{"Cookie":["REDACTED"],"Referer":["https://test.wanvb.com/UKEYA.php"],"Sec-Fetch-Site":["cross-site"],"Sec-Fetch-Mode":["cors"],"Accept":["*/*"],"Content-Length":["138"],"Cache-Control":["no-cache"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF XWEB/8391"],"Content-Type":["application/json"],"Sec-Fetch-Dest":["empty"],"Accept-Language":["zh-cn"],"Xweb_xhr":["1"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"","server_name":"test.wanvb.com"}},"bytes_read":138,"user_id":"","duration":0.0221012,"size":6,"status":200,"resp_headers":{"X-Powered-By":["PHP/8.2.0"],"Date":["Sat, 01 Feb 2025 14:36:03 GMT"],"Content-Type":["text/html; charset=utf-8"],"Server":["Caddy","nginx"],"Alt-Svc":["h3=\":443\"; ma=2592000"]},"method":"POST","postbody":"","area":"dynamic"}
Regardless of whether I turn on the debug mode, Postbody is empty, and I don’t know where the problem is.
I tried Content-Type: Application/X-WWW-FORM-Urlencoded Method POST Submit index=0&isActive=false&age=21&eyeColor=blue&test=123
Try the Content-Type: Application/JSON method post submit {“Index”: 0, “Isactive”: false, “Age”: 21, “Eyecolor”: “Blue”} log postbody records are also empty,
I hope the management master will help guide how I set it up to correctly record the content of the HTTP POST’s request body to the log? Thank you so much.
Because my back -end system often has an attacker to initiate POST malicious injection code for attack, I need to analyze the POST content they submitted, and then do targeted filtering and prevention. Power, this record is very useful. It can be recorded normally on nginx using $ Request_body variables, but currently I can’t successfully set the record on Caddy
[/quote]