nginx 502,服务器超时跟踪

近日腾讯老是报充值服务超时,但是查nginx日志,又不见具体的日志来,很是奇怪

1.在nginx中加访问日志,开始以为502这种超时不会有日志,结果发现还是有的):

10.105.24.130 - - [15/Aug/2016:15:16:10 +0800] "GET /Api_QQPayTest/pay HTTP/1.1" 502 172 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2"

目前只在access_log

access_log  /data/logs/pay.log  ;

2.怀疑php的脚本是不是有超时的情况,毕竟生产环境各种可能都有, 加上php-fpm 慢日志

slowlog = /data/logs/$pool.log.slow

 request_slowlog_timeout = 10s
 
request_terminate_timeout = 20s

3.测试:

将脚本sleep(20);这样肯定是超时的

发请求测试:

 
[root@VM_24_130_centos ~]# curl 'http://10.0.0.200:9001/test/'
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.4.4</center>
</body>
</html>
You have mail in /var/spool/mail/root
[root@VM_24_130_centos ~]# 

同时发现慢日志

[root@VM_70_200_centos Api]# tail -f /data/logs/www.log.slow 

[15-Aug-2016 15:16:00]  [pool www] pid 22915
script_filename = /data/htdocs/web/index.php
[0x00007fa976fdb498] sleep() /data/htdocs/web/controllers/test.php:117
[0x00007ffc6fd89770] test() unknown:0
[0x00007fa976fdb390] run() /data/htdocs/web/index.php:25

4.收工等生产环境日志来

5.参考 这里有更好的方案,加上php-fpm的执行时间 这里

Leave a Reply

Your email address will not be published. Required fields are marked *