1、当 pa_log 的数据长度为:6.16 GB 时,如图1

2、获取日志列表的第一页,响应时间为:1000ms 左右,是可以接受的,如图2

3、获取日志列表的最后一页,响应超时:504 Gateway Time-out,如图3

<html>
<head>
<title>504 Gateway Time-out</title>
</head>
<body bgcolor="white">
<center>
<h1>504 Gateway Time-out</h1>
</center>
<hr>
<center>nginx/1.10.1</center>
</body>
</html>
4、手动执行 SQL,其查询时间长度为:57.715s,如图4

5、实现日志消息的自动定时删除,参考网址:https://www.shuijingwanwq.com/2019/10/09/3550/ ,避免日志表的数据量无限递增。
6、参考网址:https://easycloudsupport.zendesk.com/hc/en-us/articles/360002057472-How-to-Fix-504-Gateway-Timeout-using-Nginx ,查看 C:\php-7.2.14\php.ini ,max_execution_time = 300,这设置了脚本被解析器中止之前允许的最大执行时间,单位秒,无需调整。
7、在 Nginx 虚拟主机配置中添加 fastcgi_read_timeout 变量,编辑 C:\nginx-1.10.1\conf\vhosts\pcs-api.conf
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
fastcgi_read_timeout 300;
}
8、重新加载 Nginx 配置,执行命令
PS C:\nginx-1.10.1> .\nginx -s reload
9、获取日志列表的最后一页,响应时间为:1m 左右,未响应超时,如图5

10、在浏览器中访问的是前端网址,前端基于 Nginx 反向代理至接口,在 Postman 中访问前端,获取日志列表的最后一页,响应时间为:1m 左右,未响应超时,如图6

11、在生产环境中,基于 Docker 部署,操作系统为 CentOS,获取日志列表的最后一页,响应超时:504 Gateway Time-out,如图7

<html>
<body>
<h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body>
</html>
12、查看 phpinfo(),max_execution_time 的值为 60,编辑 Dockerfile,进而编辑 /usr/local/php/etc/php.ini ,max_execution_time = 300,这设置了脚本被解析器中止之前允许的最大执行时间,单位秒。如图8

RUN sed -i 's/open_basedir = .\/:\/sobey:\/tmp:\/data:\/webtv/;open_basedir = .\/:\/sobey:\/tmp:\/data:\/webtv:\/usr\/local\/php/g' /usr/local/php/etc/php.ini && \
sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && \
sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini && \
sed -i 's/max_execution_time = 60/max_execution_time = 300/g' /usr/local/php/etc/php.ini && \
sed -i 's/pm.max_children = 20/pm.max_children = 40/g' /usr/local/php/etc/php-fpm.conf
13、在 Nginx 虚拟主机配置中添加 fastcgi_read_timeout 变量,编辑 /etc/nginx/conf.d/pcs-api.conf
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;
}
14、获取日志列表的最后一页,仍然响应超时,未符合预期,编辑 Dockerfile,进而编辑 /usr/local/php/etc/php-fpm.conf ,request_terminate_timeout = 300,如图9

RUN sed -i 's/open_basedir = .\/:\/sobey:\/tmp:\/data:\/webtv/;open_basedir = .\/:\/sobey:\/tmp:\/data:\/webtv:\/usr\/local\/php/g' /usr/local/php/etc/php.ini && \
sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && \
sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini && \
sed -i 's/max_execution_time = 60/max_execution_time = 300/g' /usr/local/php/etc/php.ini && \
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 300/g' /usr/local/php/etc/php-fpm.conf && \
sed -i 's/pm.max_children = 20/pm.max_children = 40/g' /usr/local/php/etc/php-fpm.conf
15、获取日志列表的最后一页,仍然响应超时:504 Gateway Time-out,查看响应头,发现在到达接口服务器之前,经过了网关:Kong,如图10

X-Kong-Upstream-Latency: 50005
X-Kong-Proxy-Latency: 0
Via: kong/0.12.3
16、在容器内部获取日志列表的最后一页,未超时,因此,可以确认原因出在网关:Kong 上面,有待于运维人员解决了。如图11

curl "http://127.0.0.1/v1/logs?login_id=2e368664c41b8bf511bcc9c65d86dbc3&login_tid=121f3d1986aa1c0df8f34793d928e042&page=41780"
17、还原步骤 14 所做的更改后,在容器内部获取日志列表的最后一页,仍然未超时。
Linux 服务器运维、部署与线上故障排查
如果你的网站或后端服务部署在 Linux 服务器上,遇到访问异常、Nginx 配置问题、MySQL / Redis 异常、Docker 服务不可用、磁盘占满、CPU / 内存过高等问题,可以联系我做一次远程排查。
适合以下场景:
✅ 网站打不开或访问不稳定
✅ Nginx / PHP-FPM 配置异常
✅ MySQL / Redis 性能或连接问题
✅ Docker 服务部署与维护
✅ 服务器迁移与环境配置
✅ CPU / 内存 / 磁盘异常排查
服务内容:
✅ Linux 环境检查
✅ 网站部署与迁移
✅ Nginx / PHP-FPM / MySQL / Redis 排查
✅ Docker 配置与维护
✅ 服务器性能分析
✅ 长期远程运维支持
如需咨询,请联系我,并注明:Linux 运维咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

发表回复