nginx+fpm记录php的error log

将架构从apache+mod_php迁移到nginx+fpm上,会发现如果php脚本出错,nginx的eror_log里不会有记录,只在access_log里记录了500状态码。出现的原因:nginx将php的脚本执行通过fastcgi转到fpm上,所以出错的信息当然不会记录在nginx的error_log里了,但是对于测试环境下程序员的调试这是个悲剧啊,所以我们需要配置fpm的错误日志

nginx+fastcgi+fpm配置见:

php5-fpm.conf

php5-fpm的错误日志是在php5-fpm.conf全局配置中进行设置,查看一下php5-fpm.conf日志:

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
;pid = run/php-fpm.pid
pid = /var/run/php5-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
; error_log = log/php-fpm.log
#配置error_log,设置error_log的存放位置
error_log = /var/log/fpm/php5-fpm.error.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
#错误级别(生产环境下应该提高错误级别,推荐error)
log_level = notice

#表示在emergency_restart_interval所设时间内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过emergency_restart_threshold个,php-fpm就会优雅重启
emergency_restart_threshold = 60
emergency_restart_interval = 60s

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0

; The maximum number of processes FPM will fork. This has been design to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
; process.max = 128

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
#后台执行fpm,设置为yes
daemonize = yes

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b80cdbc4a1f325c2678b99488c45fbb3.html