php+nginx服務發生500、502錯誤如何排查

概述

當線上的服務中訪問中出現500或者502錯誤時,需要緊急處理,排查問題,該怎么做?可以通過分析一些錯誤日志或者跟蹤php-fpm進程來進行問題定位。

nginx error_log

nginx的error_log在nginx的配置文件中定義的

server?{ ?listen??80; ?server_name?localhost; ?root???/var/www;  ?access_log?/users/jiao/logs/default.access.log; ?error_log?/users/jiao/logs/default.error.log; ?location?/?{ ??index?index.html?index.htm?index.php; ??autoindex?on; ?} ?location?=?/info?{ ??allow?127.0.0.1; ??deny?all; ??rewrite?(.*)?/.info.php; ?} ?location?~?.php$?{ ??root?/var/www; ??fastcgi_pass?127.0.0.1:9000; ??fastcgi_index?index.php; ??fastcgi_param?script_filename?/var/www$fastcgi_script_name; ??include?/usr/local/etc/nginx/fastcgi_params; ?} }

查看error_log

?? tail /users/jiao/logs/default.error.log
2019/07/17 11:08:18 [error] 77416#0: *76 kevent() reported about an closed connection (54: connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: “get / http/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “localhost”

發現出現了connection reset by peer,連接被重置了,此時可以再查看php-fpm的error_log進一步分析問題

php-fpm error_log

php-fpm的error_log在php-fpm.conf文件中配置中定義的

;?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?/usr/local/var ;?default?value:?log/php-fpm.log error_log?=?log/php-fpm.log

error_log里面的內容是這樣的

??tail?/usr/local/var/log/php-fpm.log [17-jul-2019?10:49:54]?notice:?[pool?www]?child?81948?started [17-jul-2019?11:08:18]?warning:?[pool?www]?child?77537,?script?'/var/www/index.php'?(request:?"get?/index.php")?execution?timed?out?(3.801267?sec),?terminating [17-jul-2019?11:08:18]?warning:?[pool?www]?child?77537?exited?on?signal?15?(sigterm)?after?1503.113967?seconds?from?start [17-jul-2019?11:08:18]?notice:?[pool?www]?child?94339?started

可以看到是請求/var/www/index.php文件出現了超時

dtruss

dtruss是動態跟蹤命令,可以根據pid,name跟蹤進程

mac環境下使用dtruss,linux環境可以使用strace,pstack

??dtruss? usage:?dtruss?[-acdefholls]?[-t?syscall]?{?-p?pid?|?-n?name?|?command?|?-w?name?}
??-p?pid???#?examine?this?pid ??-n?name???#?examine?this?process?name ??-t?syscall??#?examine?this?syscall?only ??-w?name???#?wait?for?a?process?matching?this?name ??-a????#?print?all?details ??-c????#?print?syscall?counts ??-d????#?print?relative?times?(us) ??-e????#?print?elapsed?times?(us) ??-f????#?follow?children ??-l????#?force?printing?pid/lwpid ??-o????#?print?on?cpu?times ??-s????#?print?stack?backtraces ??-l????#?don't?print?pid/lwpid ??-b?bufsize??#?dynamic?variable?buf?size

eg,

?dtruss?df?-h??#?run?and?examine?"df?-h" ?dtruss?-p?1871??#?examine?pid?1871 ?dtruss?-n?tar??#?examine?all?processes?called?"tar" ?dtruss?-f?test.sh?#?run?test.sh?and?follow?children

跟蹤php-fpm:sudo dtruss -a -n php-fpm

此時訪問web頁面,就可以看到跟蹤內容

21416/0x3479b6:??1559??63??3?getrusage(0x0,?0x7ffee1ec0760,?0x0)???=?0?0 21416/0x3479b6:??1561??4??0?getrusage(0xffffffffffffffff,?0x7ffee1ec0760,?0x0)???=?0?0 21416/0x3479b6:??1627??77??17?poll(0x7ffee1ec08c0,?0x1,?0x1388)???=?1?0 dtrace:?error?on?enabled?probe?id?2174?(id?159:?syscall::read:return):?invalid?kernel?access?in?action?#13?at?dif?offset?68 dtrace:?error?on?enabled?probe?id?2174?(id?159:?syscall::read:return):?invalid?kernel?access?in?action?#13?at?dif?offset?68 dtrace:?error?on?enabled?probe?id?2174?(id?159:?syscall::read:return):?invalid?kernel?access?in?action?#13?at?dif?offset?68 dtrace:?error?on?enabled?probe?id?2174?(id?159:?syscall::read:return):?invalid?kernel?access?in?action?#13?at?dif?offset?68 dtrace:?error?on?enabled?probe?id?2174?(id?159:?syscall::read:return):?invalid?kernel?access?in?action?#13?at?dif?offset?68 21416/0x3479b6:??1872??29??24?lstat64("/var/www/index.php

色婷婷久久综合中文久久一本|
国产免费久久久久久无码|
国产精品一区二区久久|
亚洲精品国精品久久99热一|
2021少妇久久久久久久久久|
久久人人爽人人爽人人片AV麻豆|
久久91这里精品国产2020|
久久久WWW成人免费精品|
综合久久给合久久狠狠狠97色
|
国产午夜久久影院|
久久久91人妻无码精品蜜桃HD|
久久久久一本毛久久久|
久久久久久久免费视频|
少妇久久久久久久久久|
AAA级久久久精品无码片|
国产精品九九久久免费视频
|
久久国产免费观看精品|
狠狠色伊人久久精品综合网|
久久国产精品成人免费|
久久人人超碰精品CAOPOREN|
欧美日韩精品久久久久|
精品久久久中文字幕人妻|
久久99国产精品久久99|
久久久久人妻一区精品果冻|
婷婷久久综合九色综合九七|
四虎国产精品免费久久|
亚洲国产精品久久66|
久久天天躁狠狠躁夜夜2020一|
久久久久久久尹人综合网亚洲|
久久久久久国产精品美女|
日本强好片久久久久久AAA|
久久精品国产国产精品四凭|
欧美精品福利视频一区二区三区久久久精品
|
久久久一本精品99久久精品88|
国产欧美久久久精品|
久久国产欧美日韩精品|
久久久久国产精品嫩草影院|
久久久久高潮综合影院|
四虎影视久久久免费观看|
国产一区二区精品久久岳|
99国产精品久久久久久久成人热|