nginx 502错误和504错误 [英] nginx 502 error and 504 error

查看:88
本文介绍了nginx 502错误和504错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器是node.js,我使用nginx作为反向代理.

My server is node.js and I use nginx as a reverse proxy.

现在,我必须执行一个耗时的https请求,但始终会收到504网关超时错误.和nginx/error.log说:
上游超时"

Now I have to do a time-consuming https request, but I always get the 504 Gateway Time-out error. and nginx/error.log says:
"upstream timed out"

所以我将nginx conf更改为:
proxy_read_timeout 600;
proxy_connect_timeout 600;
client_max_body_size 32M;
client_body_buffer_size 512k;
proxy_send_timeout 600;
proxy_buffers 32 4k;
这次不会出现504错误,但会变成502错误,nginx/error表示:
上游过早关闭的连接"
而且我发现错误仅在我启动120秒请求后出现.
我的请求过程肯定会超过120s,因为它将执行耗时的mysql查询.

So I change nginx conf to:
proxy_read_timeout 600;
proxy_connect_timeout 600;
client_max_body_size 32M;
client_body_buffer_size 512k;
proxy_send_timeout 600;
proxy_buffers 32 4k;
This time there will be no 504 error, but it turn to be 502 error, and nginx/error says:
"upstream prematurely closed connection"
And I find the error will just appear after I start the request for 120s.
My request process will sure take more than 120s, because it will do a time-consuming mysql query.

所以我不知道如何摆脱502错误.

So I do not know how to get rid of the 502 error.

推荐答案

根据您的描述,问题出在服务器上.您需要同时在Nginx和Web服务器上设置超时. 默认情况下,节点的默认超时为2分钟.

From what you describe, you problem is on the server now. You need to set the timeout both on nginx and t he web server. By default, node has a default timeout of 2 minutes.

查看server.setTimeout选项: http://nodejs.org/api/http. html#http_server_settimeout_msecs_callback

Look at the server.setTimeout option: http://nodejs.org/api/http.html#http_server_settimeout_msecs_callback

希望这会有所帮助.

这篇关于nginx 502错误和504错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆