Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx 502 error and 504 error

Tags:

nginx

timeout

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

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"

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.

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

like image 879
user3172936 Avatar asked Mar 19 '23 04:03

user3172936


1 Answers

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.

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

Hope this helps.

like image 162
Mihai Ionescu Avatar answered Mar 20 '23 16:03

Mihai Ionescu