nginx使用proxy模塊時(shí),默認(rèn)的讀取超時(shí)時(shí)間是60s。
1. send_timeout
syntax: send_timeout the time
default: send_timeout 60
context: http, server, location
Directive assigns response timeout to client. Timeout is established not on entire transfer of answer, but only between two operations of reading, if after this time client will take nothing, then nginx is shutting down the connection.
2. 負(fù)載均衡配置時(shí)的2個(gè)參數(shù):fail_timeout和max_fails
這2個(gè)參數(shù)一起配合,來(lái)控制nginx怎樣認(rèn)為upstream中的某個(gè)server是失效的當(dāng)在fail_timeout的時(shí)間內(nèi),某個(gè)server連 接失敗了max_fails次,則nginx會(huì)認(rèn)為該server不工作了。同時(shí),在接下來(lái)的 fail_timeout時(shí)間內(nèi),nginx不再將請(qǐng)求分發(fā)給失效的server。
個(gè)人認(rèn)為,nginx不應(yīng)該把這2個(gè)時(shí)間用同一個(gè)參數(shù)fail_timeout來(lái)控制,要是能再增加一個(gè)fail_time,來(lái)控制接下來(lái)的多長(zhǎng)時(shí)間內(nèi),不再使用down掉的server就更好了~
如果不設(shè)置這2個(gè)參數(shù),fail_timeout默認(rèn)為10s,max_fails默認(rèn)為1。就是說(shuō),只要某個(gè)server失效一次,則在接下來(lái)的10s內(nèi),就不會(huì)分發(fā)請(qǐng)求到該server上
syntax: proxy_connect_timeout timeout_in_seconds
context: http, server, location
This directive assigns a timeout for the connection to the proxyserver. This is not the time until the server returns the pages, this is the proxy_read_timeout statement. If your proxyserver is up, but hanging (e.g. it does not have enough threads to process your request so it puts you in the pool of connections to deal with later), then this statement will not help as the connection to the server has been made. It is necessary to keep in mind that this time out cannot be more than 75 seconds.
syntax: proxy_read_timeout the_time
default: proxy_read_timeout 60
context: http, server, location
This directive sets the read timeout for the response of the proxied server. It determines how long NGINX will wait to get the response to a request. The timeout is established not for entire response, but only between two operations of reading.
In contrast to proxy_connect_timeout, this timeout will catch a server that puts you in it's connection pool but does not respond to you with anything beyond that. Be careful though not to set this too low, as your proxy server might take a longer time to respond to requests on purpose (e.g. when serving you a report page that takes some time to compute). You are able though to have a different setting per location, which enables you to have a higher proxy_read_timeout for the report page's location.
If the proxied server nothing will communicate after this time, then nginx is shut connection.
另一個(gè)參考:504 Gateway Time-out問(wèn)題
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 32 4k;
proxy_busy_buffers_size 64k;
聯(lián)系客服