nginx php error log 配置 查找500 錯誤

nginx與apache不一樣,在apache中可以直接指定php的錯誤日誌,那樣在php執行中的錯誤信息就直接輸入到php的錯誤日誌中,可以方便查詢。
在nginx中,nginx只對頁面的訪問做access記錄日誌。不會有php的error log 信息。nginx把對php的請求發給php-fpm fastcgi進程來處理,默認的php-fpm只會輸出php-fpm的錯誤信息,在php-fpm的errors log裏也看不到php的errorlog。
原因是php-fpm的配置文件php-fpm.conf中默認是關閉worker進程的錯誤輸出,直接把他們重定向到/dev/null,所以我們在nginx的error log 和php-fpm的errorlog都看不到php的錯誤日誌。

所以我們要進行如下的設置就能查看到nginx下php-fpm不記錄php錯誤日誌的方法:

1,修改

php-fpm.conf

error_log = /alidata/log/php/php-fpm.log

catch_workers_output = yes

2,修改 php.ini
log_errors = On
3,重啓php-fpm
service php-fpm restart


=============================================華麗的分割線=============================================

出錯信息
當調用webji的php webservicd 接口時候報錯 
1,只是在頁面上看到500的錯誤,
2,在nginx的 access log 中能看到 500 返回碼
58.247.1.218 - - [15/Aug/2016:16:05:35 +0800] "GET /?route=user/user/pay_problem HTTP/1.1" 500 112 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4"

3,而在nginx的error log中 無任何輸出

所以必須先把error log呈現出來,通過上面配置
監聽 /alidata/log/php/php-fpm.log,得到如下log
[16-Aug-2016 09:59:06] WARNING: [pool www] child 12539 said into stderr: "NOTICE: PHP message: PHP Warning:  fopen(/alidata/www/jx_financial/system/logs/error.log): failed to open stream: Permission denied in /alidata/www/jx_financial/system/library/log.php on line 6"
[16-Aug-2016 09:59:06] WARNING: [pool www] child 12539 said into stderr: "NOTICE: PHP message: PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /alidata/www/jx_financial/system/library/log.php on line 10"
[16-Aug-2016 09:59:06] WARNING: [pool www] child 12539 said into stderr: "NOTICE: PHP message: PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /alidata/www/jx_financial/system/library/log.php on line 10"
[16-Aug-2016 09:59:06] WARNING: [pool www] child 12539 said into stderr: "NOTICE: PHP message: PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /alidata/www/jx_financial/system/library/log.php on line 10"
[16-Aug-2016 09:59:06] WARNING: [pool www] child 12539 said into stderr: "NOTICE: PHP message: PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /alidata/www/jx_financial/system/library/log.php on line 10"
[16-Aug-2016 09:59:06] WARNING: [pool www] child 12539 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Call to a member function get() on a non-object in /alidata/www/jx_financial/index.php on line 114"

至此,知道是文件權限問題,
chown www:www system -R

問題解決



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章