我在长时间运行的PHP脚本方面遇到问题:
<?php
sleep(70); # extend 60s
phpinfo();
哪个在60秒后每次都被Nginx响应504 Gateway Time-out
终止。
当我检查Nginx错误时,我可以看到请求超时:
... [error] 1312#1312: *2023 upstream timed out (110: Connection timed out) while reading response header from upstream,...,upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock",...
我经历了相关的问题,并尝试增加创建以下内容的/etc/nginx/conf.d/timeout.conf
文件的超时时间:
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
fastcgi_connect_timeout 600;
我还通读了fastcgi和core模块的Nginx文档,搜索默认设置为60秒的任何配置。
我排除了client_*
超时,因为它们返回了HTTP 408
而不是HTTP 504
响应。
这是FastCGI的Nginx服务器配置部分:
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
从到目前为止的内容来看,PHP似乎不是问题,而是Nginx超时了。尽管如此,我也尝试修改PHP中的限制:
我在phpinfo()
中的值:
default_socket_timeout=600
max_execution_time=300
max_input_time=-1
memory_limit=512M
php-fpm池配置还启用了以下功能:
catch_workers_output = yes
request_terminate_timeout = 600
php-fpm日志中没有任何内容。
我还使用Amazon的Load Balancer路由到服务器,但是超时配置也从the default 60 seconds开始增加。
在所有更改过程中,我都重新启动了php-fpm和nginx。
谢谢