我需要启用访问日志,但出于合规性原因,无法在访问日志中记录敏感 GET 请求参数的数据。虽然我知道,我可以解析日志(事后)并清理它们,但这不是一个可接受的解决方案 - 因为出于合规性原因,日志不能被篡改。
如何防止“sensitive_data”参数值写入日志?这里有一些想法:
- 在 POST 请求中发送——不是 JSONP 的选项。
- 对“资源”使用新的位置规则,并设置访问日志以使用不同格式的 log_format(即不使用 $remote_addr)。请参阅此以供参考:http://nginx.org/en/docs/http/ngx_http_log_module.html http://nginx.org/en/docs/http/ngx_http_log_module.html
- 记录 $sanitized_remote_addr,并在将其写入日志之前对其进行设置(以某种方式解析 $remote_addr 或其他内容?)。我们不确定这是否容易实现。
这应该怎么做呢?
之前的答案将不再有效log_format
模块只能用于http
级别配置。
为了解决这个问题,我们可以删除log_format
配置来自location
指令并将其保留在 http 级别配置中。
http {
log_format filter '$remote_addr - $remote_user [$time_local] '
'"$temp" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
# Other Configs
}
log_format
指令可以在我们的后面定义变量location
指令块。
所以最终的配置将如下所示:
http {
log_format filter '$remote_addr - $remote_user [$time_local] '
'"$temp" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
# Other Configs
server {
#Server Configs
location / {
set $temp $request;
if ($temp ~ (.*)password=[^&]*(.*)) {
set $temp $1password=****$2;
}
access_log /opt/current/log/nginx_access.log filter;
}
}
}
请注意,错误日志可能仍会记录此信息。
使用error_logs off;
在您的位置块中禁用此功能(假设您可以在应用程序的其他位置记录这些错误)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)