nginx使用proxy模塊時,默認的讀取超時時間是60s。
1. send_timeout nginx
syntax: send_timeout the timeweb
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. 負載均衡配置時的2個參數:fail_timeout和max_failsthis
這2個參數一塊兒配合,來控制nginx怎樣認爲upstream中的某個server是失效的當在fail_timeout的時間內,某個server連 接失敗了max_fails次,則nginx會認爲該server不工做了。同時,在接下來的 fail_timeout時間內,nginx再也不將請求分發給失效的server。
我的認爲,nginx不該該把這2個時間用同一個參數fail_timeout來控制,要是能再增長一個fail_time,來控制接下來的多長時間內,再也不使用down掉的server就更好了~
若是不設置這2個參數,fail_timeout默認爲10s,max_fails默認爲1。就是說,只要某個server失效一次,則在接下來的10s內,就不會分發請求到該server上spa
syntax: proxy_connect_timeout timeout_in_secondsserver
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.rem
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.
另外一個參考:504 Gateway Time-out問題
常見於使用nginx做爲web server的服務器的網站
我遇到這個問題是在升級discuz論壇的時候遇到的
通常看來, 這種狀況多是因爲nginx默認的fastcgi進程響應的緩衝區過小形成的, 這將致使fastcgi進程被掛起, 若是你的fastcgi服務對這個掛起處理的很差, 那麼最後就極有可能致使504 Gateway Time-out
如今的網站, 尤爲某些論壇有大量的回覆和不少內容的, 一個頁面甚至有幾百K
默認的fastcgi進程響應的緩衝區是8K, 咱們能夠設置大點
在nginx.conf裏, 加入:
fastcgi_buffers 8 128k
這表示設置fastcgi緩衝區爲8×128k
固然若是您在進行某一項即時的操做, 可能須要nginx的超時參數調大點, 例如設置成60秒:
send_timeout 60;
調整了這兩個參數, 結果就是沒有再顯示那個超時, 能夠說效果不錯, 可是也多是因爲其餘的緣由, 目前關於nginx的資料不是不少, 不少事情都須要長期的經驗累計纔有結果。
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;