解决:LNMP架构下nginx的error_log日志过大问题

php-fpm.conf 中的php

catch_workers_output = yes

设置能够捕获 php 程序的错误输出
nginx

我在部署LNMP架构时都是设置此项为yes,便于日志分析架构

若是此项设置为 yes ,同时ide

error_reporting = E_ALL

的话,那么nginx的错误日志会记录大量记录,内容以下:php-fpm

2013/08/09 14:38:14 [error] 6687#0: *33365028 FastCGI sent in stderr: "PHP Notice:  Undefined variable: xxxx in /data/www/www/controllers/main.php on line 50
PHP Notice:  Undefined variable: xxxx in /data/www/www/controllers/main.php on line 55
PHP Notice:  Undefined index:  sid in /data/www/www/controllers/main.php on line 88


固然了,这是在php代码写的不够严谨的状况下,如:日志

一、直接使用开发

$sid = $_GET['sid'];

而未作 isset 判断
部署

二、使用未定义变量 it

print $username;

像这样的 E_NOTICE 类错误都会记录到nginx错误日志,日志大小增加迅速ast


比较好的解决方法是开发严谨的程序

其次就是调整错误报告的级别,如去掉 E_NOTICE 类的错误

能够在 php.ini 中设置,如:

error_reporting = E_ALL & ~E_NOTICE

便可,

配置文件中不支持

error_reporting = E_ALL ^ E_NOTICE

这种写法,可是在php程序中能够这么使用

其实即便在配置文件中设置了

error_reporting = E_ALL & ~E_NOTICE

若是同时在程序中设置,如:

error_reporting(E_ALL);

那么会以在程序中设置的为准,因此日志仍是会记录 Notice 错误的

相关文章
相关标签/搜索