1. 程式人生 > >nginx.conf配置檔案中timeout超時時間設定

nginx.conf配置檔案中timeout超時時間設定

nginx常用的超時配置說明

client_header_timeout

語法 client_header_timeout time
預設值 60s
上下文 http server(指可以放在http塊和server塊)
說明 指定等待client傳送一個請求頭的超時時間(例如:GET / HTTP/1.1).僅當在一次read中,沒有收到請求頭,才會算成超時。如果在超時時間內,client沒傳送任何東西,nginx返回HTTP狀態碼408(“Request timed out”)

client_body_timeout 
語法 client_body_timeout time
預設值 60s
上下文 http server location


說明 該指令設定請求體(request body)的讀超時時間。僅當在一次readstep中,沒有得到請求體,就會設為超時。超時後,nginx返回HTTP狀態碼408(“Request timed out”)

keepalive_timeout (長連線型別)
語法 keepalive_timeout timeout [ header_timeout ]
預設值 75s
上下文 http server location
說明 第一個引數指定了與client的keep-alive連線超時時間。伺服器將會在這個時間後關閉連線。可選的第二個引數指定了在響應頭Keep-Alive: timeout=time中的time值。這個頭能夠讓一些瀏覽器主動關閉連線,這樣伺服器就不必要去關閉連線了。沒有這個引數,nginx不會發送Keep-Alive響應頭(儘管並不是由這個頭來決定連線是否“keep-alive”)(伺服器在返回資料給使用者時,在頭header檔案中會新增keepalive欄位,75s,瀏覽器在這個時間後能夠主動關閉連線)

兩個引數的值可並不相同

  • 注意不同瀏覽器怎麼處理“keep-alive”頭

  • MSIE和Opera忽略掉"Keep-Alive: timeout=<N>" header.

  • MSIE保持連線大約60-65秒,然後傳送TCP RST

  • Opera永久保持長連線

  • Mozilla keeps the connection alive for N plus about 1-10 seconds.

  • Konqueror保持長連線N秒


lingering_timeout
語法 lingering_timeout time
預設值 5s
上下文 http server location
說明 lingering_close生效後,在關閉連線前,會檢測是否有使用者傳送的資料到達伺服器,如果超過lingering_timeout時間後還沒有資料可讀,就直接關閉連線;否則,必須在讀取完連線緩衝區上的資料並丟棄掉後才會關閉連線。



resolver_timeout
語法 resolver_timeout time 
預設值 30s
上下文 http server location
說明 該指令設定DNS解析超時時間

proxy轉發模組的超時設定:
proxy_connect_timeout
語法 proxy_connect_timeout time 
預設值 60s
上下文 http server location
說明 該指令設定與upstream server的連線超時時間,有必要記住,這個超時不能超過75秒。
這個不是等待後端返回頁面的時間,那是由proxy_read_timeout宣告的。如果你的upstream伺服器起來了,但是hanging住了(例如,沒有足夠的執行緒處理請求,所以把你的請求放到請求池裡稍後處理),那麼這個宣告是沒有用的,因為與upstream伺服器的連線已經建立了。

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.

proxy_read_timeout
語法 proxy_read_timeout time 
預設值 60s
上下文 http server location
說明 該指令設定與代理伺服器的讀超時時間。它決定了nginx會等待多長時間來獲得請求的響應。這個時間不是獲得整個response的時間,而是兩次reading操作的時間。(??什麼是兩次reading操作的時間)

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.


proxy_send_timeout
語法 proxy_send_timeout time 
預設值 60s
上下文 http server location
說明 這個指定設定了傳送請求給upstream伺服器的超時時間。超時設定不是為了整個傳送期間,而是在兩次write操作期間。如果超時後,upstream沒有收到新的資料,nginx會關閉連線

proxy_upstream_fail_timeout(fail_timeout)
語法 server address [fail_timeout=30s]
預設值 10s
上下文 upstream
說明 Upstream模組下 server指令的引數,設定了某一個upstream後端失敗了指定次數(max_fails)後,該後端不可操作的時間,預設為10秒

負載均衡配置時的2個引數:fail_timeoutmax_fails

   這2個引數一起配合,來控制nginx怎樣認為upstream中的某個server是失效的當在fail_timeout的時間內,某個server連線失敗了max_fails次,則nginx會認為該server不工作了。同時,在接下來的 fail_timeout時間內,nginx不再將請求分發給失效的server。
個人認為,n
ginx不應該把這2個時間用同一個引數fail_timeout來控制,要是能再增加一個fail_time,來控制接下來的多長時間內,不再使用down掉的server就更好了~
如果不設定這2個引數,fail_timeout預設為10s,max_fails預設為1。就是說,只要某個server失效一次,則在接下來的10s內,就不會分發請求到該server上

send_timeout

預設:send_timeout 60;

send_timeout 指定客戶端的響應超時時間。這個設定不會用於整個轉發器,而是在兩次客戶端讀取操作之間。如果在這段時間內,客戶端沒有讀取任何資料,nginx就會關閉連線。

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.

另一個參考: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;

相關推薦

nginx.conf配置檔案timeout超時時間設定

nginx常用的超時配置說明client_header_timeout語法 client_header_timeout time預設值 60s上下文 http server(指可以放在http塊和server塊)說明 指定等待client傳送一個請求頭的超時時間(例如:GET

關於nginx配置負載均衡,nginx.conf配置檔案正確,一直跳出nginx歡迎介面

小編跟大家一樣,明明配置檔案正確,但就是一直跳出nginx歡迎介面 這個是我nginx的安裝目錄,我在這個目錄下吧nginx.conf修改配置,發現沒用。     於是我看了nginx啟動命令 /usr/local/nginx/sbin/nginx 。我

Nginx.conf配置檔案

清空之前配置檔案; # > /usr/local/nginx/conf/nginx.conf # vim /usr/local/nginx/conf/nginx.conf user nobody nobody; worker_processes 2; error_

Nginx.conf配置檔案詳解

執行使用者 user nobody; 啟動程序,通常設定成和cpu的數量相等 worker_processes 1; 全域性錯誤日誌及PID檔案 error_log logs/error.log; error_log logs/error.log not

nginx.conf 配置檔案詳解

######Nginx配置檔案nginx.conf中文詳解##### #定義Nginx執行的使用者和使用者組 user www www; #nginx程序數,建議設定為等於CPU總核心數。 worker_processes 8; #全域性錯誤日誌定義型別

01 Nginx安裝 nginx下部署專案,nginx conf配置檔案修改,相關檔案配置

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!                2 下載pcre,這個是一個正則表示式的庫,Nginx做rewriter的時候回用到這個庫:選中右擊複製所需要的版本:4.將下面安裝檔案上傳到Linux伺服

docker安裝_進入容器修改nginx.conf配置檔案_宿主主機掛載(nginx舉例)

前言 1、docker安裝Nginx 1.1、觀察nginx是否可下載 healerjean$ docker search nginx 1.2、開始安裝 healerjean$ docker pull nginx 2

Nginxnginx.conf配置檔案中文註釋說明

#執行使用者 user www-data; #啟動程序,通常設定成和cpu的數量相等 worker_processes 1; #全域性錯誤日誌及PID檔案 error_log /var/log/nginx/e

HTTP伺服器Nginx.conf配置檔案介紹與除錯

Nginx配置檔案主要分成四部分:main(全域性設定)、server(主機設定)、upstream(負載均衡伺服器設定)和 location(URL匹配特定位置的設定)  Nginx安裝完畢後,會產生相應的安裝目錄,根據前面的安裝路徑,Nginx的配置檔案路徑為/opt

nginx.conf配置檔案解析(http、server、location)

nginx.conf檔案在安裝目錄/conf目錄下 1、定義Nginx執行的使用者和使用者組 user nginx nginx; 2、nginx程序數,建議設定為等於CPU總核心數 worker_processes 1; 3、全域性錯誤日誌

LinuxNginx配置檔案nginx.conf詳解

原文地址:https://blog.csdn.net/GP_666/article/details/79971198user www www; #制定nginx 執行的使用者名稱和使用者組 worker_processes 4; #nginx 程序數   建議設定

NGINX conf 配置文件的變量大全 可用變量列表及說明

remote 就是 否則 gin href method 自變量 c module 文件中 $args #這個變量等於請求行中的參數。$content_length #請求頭中的Content-length字段。$content_type #請求頭中的Con

Spring Boot Cache + redis 設定有效時間和自動重新整理快取,時間支援在配置檔案配置

分享一下我老師大神的人工智慧教程吧。零基礎,通俗易懂!風趣幽默!http://www.captainbed.net/ 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

Nginx配置檔案nginx.conf超詳細中文詳解

第1章 簡介 第2章 nginx配置解釋圖解 第3章 Nginx核心配置檔案nginx.conf史上最細中文詳解 3.1 定義Nginx執行的使用者和使用者組 3.2 nginxworker程序數,即處理請求的程序(熟稱負責接客的服務員) 3.3 c

nginx配置檔案引數的作用

####預設的nobody,沒有訪問目錄許可權,然後指定有許可權的使用者 ####user nobody; ####一般一個程序足夠了,你可以把連線數設得很大。 ####如果有SSL、gzip這些比較消耗CPU的工作,而且是多核CPU的話,可以設為和CPU的數

Nginx配置檔案的匹配規則例項

先來個具體的例項 server { listen 8000; server_name www; location / { echo "first"; } } serv

nginx配置檔案去掉指定目錄下面php的字尾

location ^~ /api/ { if (!-f $request_filename){ rewrite "^/api/(.*)$" /api/$1.php;

nginx動態分離conf配置檔案

動靜分離,即nginx處理靜態資源(jss、ccc、圖片等),其餘的交tomcat處理 (如下配置檔案) user www www; worker_processes auto; error_log /data/wwwlogs/error_nginx.log crit;

Spring Boot快取實戰 Redis 設定有效時間和自動重新整理快取,時間支援在配置檔案配置

問題描述 Spring Cache提供的@Cacheable註解不支援配置過期時間,還有快取的自動重新整理。 我們可以通過配置CacheManneg來配置預設的過期時間和針對每個快取容器(value)單獨配置過期時間,但是總是感覺不太靈活。下面是一個示例: @Bean

nginx配置檔案$request_uri到底是指的url裡哪部分

我經過反覆測試,結合在log裡新增$request_uri變數,得出結論,這個$request_uri就是完整url中刨去最前面$host剩下的部分,比如http://www.baidu.com/pan/beta/test1?fid=3這個url,去掉www.baidu.com剩下的就是了,日誌裡會看到打印出