我在一个长时间运行的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=512Mphp-fpm池配置还启用了以下功能:
catch_workers_output = yes
request_terminate_timeout = 600php-fpm日志中没有任何内容。
我也使用亚马逊的负载均衡器来路由到服务器,但超时配置也从the default 60 seconds增加。
我不知道还能去哪里看,在所有的更改期间,我重启了php-fpm和nginx。
谢谢
发布于 2020-01-14 05:01:12
在这些情况下,我实际上编辑了一个错误的配置文件,该文件没有被Nginx加载。
将以下代码添加到正确的文件中确实起到了作用:
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
fastcgi_connect_timeout 600;https://stackoverflow.com/questions/59713432
复制相似问题