Nginx没有loggingPHP错误

当访问我的网站上的一些PHP脚本,我得到了可怕的500错误信息。 我想知道什么是错误的,但是Nginx并没有在我指定的日志文件中logging任何PHP错误。 这是我的服务器块:

server { listen 80; server_name localhost; access_log /home/whitey/sites/localhost/logs/access.log; error_log /home/whitey/sites/localhost/logs/error.log error; root /home/whitey/sites/localhost/htdocs; index index.html index.php /index.php; location / { } location ~ \.php$ { fastcgi_pass unix:/tmp/phpfpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { expires max; } } 

请注意,一些PHP脚本工作正常,而其他人不。 所以PHP没有全局性的问题,这些脚本中只有一些导致Nginx抛出500错误。

我怎样才能做到这一点? error.log唯一的错误是关于favicon.ico的错误。

您必须将以下内容添加到您的php-fpm池configuration中:

 catch_workers_output = 1 

您必须将此行添加到每个定义的池!

php-fpm/var/log/php5-fpm.log或类似的地方抛出一切。

我有一个类似的问题。

我尝试在CentOS7上使用php-fpm 7.0和nginx来部署phpMyAdmin。 Nginx向我展示了500.html,但是在任何日志文件中都没有错误。 我做了所有这一切

 catch_workers_output = 1 

 display_errors = On 

nginx日志或php-fpm日志不包含任何错误string。

当我在nginx.conf中评论这行时,我能够在浏览器页面看到错误的东西。

 # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } 

那是帮助我理解麻烦的。

查看你的nginx.conf中的error_log定义。 也许nginx在这个错误日志里写东西。

您也可以在PHP上启用日志logging。

对我来说,这似乎是一个暴发户的问题,这是路由的日志为php-fpm到自己的自定义位置,例如:

 /var/log/upstart/php5-fpm.log 

还有一些buzziness Ubuntu的Precise,12.04可能会导致缺乏日志function: https ://bugs.php.net/bug.php?id = 61045如果你还在运行该版本。

当PHP display_errors被禁用时,PHP错误可能会返回Nginx 500错误。

你应该看看你的php-fpm日志,我相信你会发现那里的错误。 借助CentOS 7:

 tail -f /var/log/php-fpm/www-error.log 

你也可以显示PHP错误。 在你的php.ini中,改变:

 display_errors = Off 

至 :

 display_errors = On 

希望能帮助到你。

这是发生在我身上的事情:

当我删除我的错误日志时,nginx注意到它不再丢失。 当我重新创build这个文件时,nginx将不再认识到它存在,因此不写入文件。

要解决这个问题,运行这些命令(我在Ubuntu 14.04 LTS上):

 sudo service nginx reload 

如果这不起作用,那么请尝试:

 sudo service nginx restart