【问题标题】:CustomLog fails when piped to sed传送到 sed 时,CustomLog 失败
【发布时间】:2015-03-11 20:52:46
【问题描述】:

我正在尝试使用管道自定义日志来过滤我的日志:

httpd.conf

CustomLog "|/bin/sed -r s/pass/REDACTED/g >> /workplace/tmp/access.log" common 

但是,当我向 Apache 发出请求时,我收到一条错误消息

/bin/sed: can't read >>: No such file or directory 

我在这里做错了什么? (好像others have been able to use piped CustomLog like this

【问题讨论】:

  • ls /workplace/tmp/access.log 返回什么?
  • 显示文件。我确保每个人都有写权限:-rw-rw-rw-

标签: apache sed httpd.conf


【解决方案1】:

我刚刚解决了这个问题,并认为我应该在这里更新,即使这个帖子很旧。

首先,上面提示输入文件丢失的发帖人是不正确的。没有输入文件。 Apache 通过管道而不是文件将日志消息发送到 sed。

这里的技巧是告诉 apache 为 sed 命令启动一个 shell。在不启动 shell 的情况下,“>>”没有特殊含义,被视为文件名。要告诉 apache 为 sed 启动一个 shell,您可以在管道符号后附加一个“$”,如下所示:

CustomLog "|$/bin/sed s/'creditCardPAN=[^ ]*'/'creditCardPAN=REDACTED'/ >>logs/ssl_access_log" PaymentLogFormat

【讨论】:

    【解决方案2】:

    我认为您缺少输入文件。应该是:

    sed -r s/pass/REDACTED/g myInputFile.txt >> /workplace/tmp/access.log
    

    【讨论】:

      【解决方案3】:

      为了我们的 PCI-DSS 合规性,我在使用此自定义日志写入之前从日志中删除每个 16 位序列

      CustomLog '|$/usr/bin/sed -r \"s:\([345][0-9]{5}\)\([0-9]{6}\)\([0-9]{4}\):\\\1******\\\3:g\" >> logs/access_log' common
      

      PS:我不检查 luhn 校验和

      检查

      curl https://<instance>/A3000001111112222B -> GET /A300000******2222B

      curl https://<instance>/A32345612345612343234561234561234B -> GET /A323456******1234323456******1234

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-25
        • 2020-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多