在 Apache 中记录 POST 数据的最佳方式? [英] Best way to log POST data in Apache?
问题描述
假设您有一个站点 API,它以带参数的 GET 请求或 POST 请求(例如,使用标准 url 编码、& 分隔的 POST 数据)接受数据.如果您想记录和分析 API 调用,GET 请求将很容易,因为它们将在 apache 日志中.是否有一种简单的方法也可以在 apache 日志中获取 POST 数据?
Imagine you have a site API that accepts data in the form of GET requests with parameters, or as POST requests (say, with standard url-encoded, &-separated POST data). If you want to log and analyze API calls, the GET requests will be easy, because they will be in the apache log. Is there a simple way to get the POST data in the apache log as well?
(当然,我们可以在应用程序中显式记录 POST 数据,但我希望有一种配置级别的方式,让我不必在代码中担心它.)
(Of course we could log the POST data explicitly in the application, but I'd like to have an configuration-level way that let me not worry about it in code.)
推荐答案
使用 Apache 的 mod_dumpio.出于显而易见的原因要小心.
Use Apache's mod_dumpio. Be careful for obvious reasons.
注意 mod_dumpio 停止记录第一个空字符处的二进制负载.例如,multipart/form-data
上传一个 gzip 文件可能只显示带有 mod_dumpio 的前几个字节.
Note that mod_dumpio stops logging binary payloads at the first null character. For example a multipart/form-data
upload of a gzip'd file will probably only show the first few bytes with mod_dumpio.
另请注意,Apache 可能不会在 httpd.conf
中提及此模块,即使它存在于 /modules
文件夹中.只需手动添加 LoadModule
即可正常工作.
Also note that Apache might not mention this module in httpd.conf
even when it's present in the /modules
folder. Just manually adding LoadModule
will work fine.
这篇关于在 Apache 中记录 POST 数据的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!