Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何在nginx中将日志文件传输到python_Apache_Nginx_Logging_Pipe - Fatal编程技术网

Apache 如何在nginx中将日志文件传输到python

Apache 如何在nginx中将日志文件传输到python,apache,nginx,logging,pipe,Apache,Nginx,Logging,Pipe,如何将nginx日志输出通过管道传输到python脚本,而不首先将其保存到日志文件中。目前我使用apache,在那里我通过管道传输它,如下所示: CustomLog "|/path/to/script.py" 在nginx中,日志文件的配置类似于下面的代码,现在我需要将其通过管道传输到python脚本 # Nginx access file: $InputFileName /var/log/nginx/access.log $InputFileTag nginx-access: $InputF

如何将nginx日志输出通过管道传输到python脚本,而不首先将其保存到日志文件中。
目前我使用apache,在那里我通过管道传输它,如下所示:

CustomLog "|/path/to/script.py"
在nginx中,日志文件的配置类似于下面的代码,现在我需要将其通过管道传输到python脚本

# Nginx access file:
$InputFileName /var/log/nginx/access.log
$InputFileTag nginx-access:
$InputFileStateFile stat-nginx-access
$InputFileSeverity info
$InputFilePersistStateInterval 20000
$InputRunFileMonitor

#Nginx Error file: 
$InputFileName /var/log/nginx/error.log
$InputFileTag nginx-error:
$InputFileStateFile stat-nginx-error
$InputFileSeverity error
$InputFilePersistStateInterval 20000
$InputRunFileMonitor

多亏了nginx IRC频道,我找到了一个合适的解决方案,我想与下一个有同样问题的人分享

http {
  #(...)


  map $remote_addr $anon_remote_addr {
    "~^(?<ip_a>\d+\.\d+)\.\d+\.\d+" "$ip_a";
  }
  log_format combined_anon '$anon_remote_addr.0.0 - $remote_user [$time_local] '
                           '"$request" $status $body_bytes_sent '
                           '"$http_referer" "$http_user_agent"';
  # Set it globally
  access_log /var/log/nginx/access.log combined_anon;


  #(...)
}
http{
#(...)
映射$remote\u addr$anon\u remote\u addr{
“~^(?\d+\.\d+\.\d+\.\d+”“$ip\u a”;
}
日志\u格式组合\u anon'$anon\u remote\u addr.0.0-$remote\u user[$time\u local]'
“$request”$status$body\u bytes\u sent”
“$http_referer”“$http_user_agent””;
#全局设置
access\u log/var/log/nginx/access.log;
#(...)
}

代码片段:

要清楚,这是一个匿名化日志文件的解决方案,而不是将日志传输到外部程序(这就是问题所在)。