使用Apache的CustomLog进行正则表达式替换,得到未终止的's'字符错误

我正在尝试清理敏感数据的apache日志,因为它已在查询字符串参数中传递。我知道这不好,无法更改。

以下是这个问题:https://stackoverflow.com/a/9473943/1046387

这是在我的apache.conf

CustomLog "|/bin/sed -u -E s/'api_key=[^& \t\n]*'/'api_key=\[FILTERED\]'/g >> /var/log/apache2/access.log" combined

我一直收到此错误:

AH00106: piped log program '/bin/sed -u -E s/'api_key=[^& \\t\\n]*'/'api_key=\\[FILTERED\\]'/g >> /var/log/apache2/access.log' failed unexpectedly
/bin/sed: -e expression #1,char 14: unterminated `s' command

尽管能够直接在包装盒上运行命令:

$ echo "api_key=343" | /bin/sed -u -E s/'api_key=[^& \t\n]*'/'api_key=\[FILTERED\]'/g
api_key=[FILTERED]

似乎apache无法正确地将命令移交给sed,因此它缺少一些参数。转义序列有问题吗?

Linpeipei1985 回答:使用Apache的CustomLog进行正则表达式替换,得到未终止的's'字符错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167171.html

大家都在问