增加504超时错误

86

有没有办法让错误504网关超时的时间更长? 如果有,如何更改以及在哪里可以找到要更改的文件。 我正在使用CentOS 6上的nginx。


在我的情况下,我正在使用带有负载均衡器的nginx,因此我必须更新haproxy配置以增加服务器超时timeout server 3000s - fungusanthrax
2个回答

141

9
我发现 https://www.scalescale.com/tips/nginx/504-gateway-time-out-using-nginx/ 上提到了一些额外的超时设置。这也可能在这方面有所帮助。 - Jakob Runge
1
我试图首先回答这个问题。其他提到的选项与nginx无关,或者不是关于修复错误504的(除了*_connect_timeout可能...但那更多是关于网络连接问题)。 - kworr
是的,我知道这一点,我也发现你的答案对我非常有帮助。只是想说,额外的信息可能也会对其他人有所帮助。:) - Jakob Runge
1
你需要在时间后面加上's'吗?proxy_read_timeout 60s; - David Lin
1
@DavidLin,你说得对,尽管秒是默认的,但应该根据http://nginx.org/en/docs/syntax.html添加测量单位。 - kworr
请确保创建一个新文件并将其添加到 /nginx/conf.d/ 文件夹中,而不是直接编辑 /nginx/nginx.conf 文件夹。这样更便于移植,并且可以轻松查看和编辑过去的更改。 - DavidR

5
如果出现 fastcgi 超时错误,则需要增加 fastcgi_read_timeout
# /etc/nginx/conf.d/example.com.conf
server {

    location ~ \.(php)$ {
        fastcgi_pass unix:/var/run/php74-example.com.sock;
        fastcgi_read_timeout 300s;

错误日志)上游超时

# tail -f example.com.error.log
2020/12/29 14:51:42 [error] 30922#30922: 
*9494 upstream timed out (110: Connection timed out) while reading response header from upstream,
...
upstream: "fastcgi://unix:/var/run/php74-example.com.sock",
...

nginx手册

Default: fastcgi_read_timeout 60s;
Context: http, server, location

http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_read_timeout


在Chrome DevTools中运行超过60秒的脚本的结果。

默认为60秒。

enter image description here

fastcgi_read_timeout 300秒

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接