启用PHP错误日志时,将禁用NGINX错误日志

时间:2017-02-16 17:28:25

标签: php logging nginx

我遇到了一种奇怪的行为。我用PHP-FPM运行NGINX。

当我在php.ini中启用PHP错误日志时:

error_log = /var/www/logs/php-scripts.error.log
log_errors = on

错误日志按预期写入:

...
[15-Feb-2017 19:35:28 Etc/UTC] PHP Parse error:  syntax error, unexpected end of file, expecting ',' or ';' in /var/www/html/index.php on line 7

但是,同时我的NGINX vhost 中配置的错误日志根本没有写入(这是NGINX配置片段):

server {
  listen 80;
  server_name  vhost.com;

  access_log   /var/log/nginx/access.log main;
  error_log    /var/log/nginx/error.log; <- this is always empty
}

令我惊讶的是,当我在php.ini中禁用错误​​日志时:

; error_log = /var/www/logs/php-scripts.error.log <-- commented out
log_errors = on

NGINX错误日志写入

...
2017/02/16 12:01:44 [error] 13#13: *27 FastCGI sent in stderr: "PHP message: PHP Parse error:  syntax error, unexpected end of file, expecting ',' or ';' in /var/www/html/index.php on line 7" while reading response header from upstream, client: 172.19.0.2, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "domain.com:8080"

我根本不明白这种行为。这两种测井系统之间干扰的根源是什么?为什么我无法在php.ini中启用错误日志,同时还要写入NGINX的错误日志?目前它是一个或另一个。是否有可能克服这个问题?

1 个答案:

答案 0 :(得分:2)

PHP向日志文件,syslog(3)或stderr报告错误,具体取决于error_log是否以及如何设置。有关详细信息,请参阅this document

nginx将记录它通过FastCGI stderr流接收的消息。

所以,这并不是一种奇怪的行为。

相关问题