Nginx 504 Gateway Time-out/xxxx方法

注:除了f12,日志等。不要相信任何彈窗。。
問題描述:接到用戶反饋,彈窗提示文件導(dǎo)入失敗
解決途徑:
1、拿到用戶賬號(hào)密碼及相關(guān)excel后,還原業(yè)務(wù)操作,f12發(fā)現(xiàn)報(bào)錯(cuò)信息504 Gateway Time-out/xxxx
2、nginx504超時(shí),查看tomcat日志,根據(jù)業(yè)務(wù)定位日志
業(yè)務(wù)開始:


Snipaste_2021-04-25_17-04-28.png

業(yè)務(wù)結(jié)束:


Snipaste_2021-04-25_17-06-11.png

所用時(shí)間:大約為2min

3、查看nginx默認(rèn)超時(shí)時(shí)間
proxy_connect_timeout
語法: proxy_connect_timeout timeout_in_seconds
上下文: 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 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.
該指令為到 代理服務(wù)器的連接分配一個(gè)超時(shí)。這不是服務(wù)器返回頁面的時(shí)間。如果 代理服務(wù)器 已經(jīng)啟動(dòng),但是掛起了(例如,它沒有足夠的線程來處理您的請(qǐng)求,因此它將您放在連接池中,以便以后處理) ,那么這條語句將不會(huì)有任何幫助,因?yàn)橐呀?jīng)建立了與服務(wù)器的連接。有必要記住,這個(gè)超時(shí)時(shí)間不能超過75秒。
注:這個(gè)應(yīng)該是建立三次握手連接時(shí)間,設(shè)置不能超過75S

proxy_send_timeout
語法: proxy_send_timeout time_in_seconds
默認(rèn)值: proxy_send_timeout 60
上下文: http, server, location
This directive assigns timeout with the transfer of request to the proxy server. Time out is established not on entire transfer of request, but only between two operations of record. If after this time the proxy server will not take new data, then nginx is shut the connection
個(gè)人理解:有錯(cuò)請(qǐng)指出。
該指令通過向代理服務(wù)器傳輸請(qǐng)求來分配超時(shí)時(shí)間。超時(shí)不是在整個(gè)請(qǐng)求傳輸上建立的,而是僅在兩個(gè)請(qǐng)求操作之間建立的。如果在此之后代理服務(wù)器將不接受新數(shù)據(jù),那么 nginx 將關(guān)閉連接。(比如文件上傳,60s內(nèi)沒把數(shù)據(jù)傳給upstram)

proxy_read_timeout
語法: proxy_read_timeout the_time
默認(rèn)值: proxy_read_timeout 60
上下文: 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 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 proxyserver 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.
此指令設(shè)置代理服務(wù)器響應(yīng)的讀取超時(shí)。它確定 NGINX 將等待多長(zhǎng)時(shí)間才能得到請(qǐng)求的響應(yīng)。超時(shí)不是針對(duì)整個(gè)響應(yīng)設(shè)置的,而是僅在兩個(gè)讀取操作之間設(shè)置的。
與[ # proxy connect timeout proxy proxy connect timeout ]相反,這個(gè)超時(shí)將捕獲一個(gè)服務(wù)器,它將把你放入它的連接池,但除此之外不會(huì)對(duì)你做出任何響應(yīng)。不過要小心,不要設(shè)置得太低,因?yàn)?proxyserver 可能需要更長(zhǎng)的時(shí)間故意響應(yīng)請(qǐng)求(例如,當(dāng)為您提供一個(gè)需要花費(fèi)一些時(shí)間進(jìn)行計(jì)算的報(bào)告頁面時(shí))。不過,您可以為每個(gè)位置設(shè)置一個(gè)不同的設(shè)置,這樣就可以為報(bào)表頁面的位置設(shè)置更高的代理讀取超時(shí)。
如果被代理的服務(wù)器在這個(gè)時(shí)間之后沒有任何東西進(jìn)行通信,那么 nginx 關(guān)閉連接。60s內(nèi)沒從upstream讀到任何數(shù)據(jù)。兩臺(tái)負(fù)載情況下,默認(rèn)容錯(cuò)機(jī)制表現(xiàn)給瀏覽器就是120s返回504。只針對(duì)GET生效,針對(duì)POST請(qǐng)求,需要增加 non_idempotent

容錯(cuò)參數(shù):
句法: proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429 | non_idempotent | off ...;
默認(rèn):
proxy_next_upstream 錯(cuò)誤超時(shí);
語境: http, server,location
指定在哪些情況下應(yīng)將請(qǐng)求傳遞到下一個(gè)服務(wù)器:

error
與服務(wù)器建立連接、向其傳遞請(qǐng)求或讀取響應(yīng)頭時(shí)發(fā)生錯(cuò)誤;
timeout
與服務(wù)器建立連接、向其傳遞請(qǐng)求或讀取響應(yīng)標(biāo)頭時(shí)發(fā)生超時(shí);
invalid_header
服務(wù)器返回空或無效的響應(yīng);
http_500
服務(wù)器返回代碼為 500 的響應(yīng);
http_502
服務(wù)器返回代碼為 502 的響應(yīng);
http_503
服務(wù)器返回代碼為 503 的響應(yīng);
http_504
服務(wù)器返回代碼為 504 的響應(yīng);
http_403
服務(wù)器返回代碼為 403 的響應(yīng);
http_404
服務(wù)器返回代碼為 404 的響應(yīng);
http_429
服務(wù)器返回代碼為 429 (1.11.13) 的響應(yīng);
non_idempotent
通常,如果請(qǐng)求已發(fā)送到上游服務(wù)器 (1.9.13) ,則使用 非冪等 方法 ( POST, LOCK, PATCH) 的請(qǐng)求不會(huì)傳遞到下一個(gè)服務(wù)器;顯式啟用此選項(xiàng)允許重試此類請(qǐng)求;
off
禁止將請(qǐng)求傳遞到下一個(gè)服務(wù)器。
應(yīng)該記住,只有在尚未向客戶端發(fā)送任何內(nèi)容的情況下,才能將請(qǐng)求傳遞到下一個(gè)服務(wù)器。也就是說,如果在傳輸響應(yīng)的過程中發(fā)生錯(cuò)誤或超時(shí),則無法修復(fù)此問題。

該指令還定義了與服務(wù)器通信的 失敗嘗試。的情況下error,timeout并 invalid_header始終被認(rèn)為不成功的嘗試,即使在該指令中沒有指定他們。的情況下http_500,http_502, http_503,http_504,和http_429被認(rèn)為只有當(dāng)他們?cè)谠撝噶钪兄付ú怀晒Φ膰L試。的情況下,http_403和http_404 永遠(yuǎn)不會(huì)被視為不成功的嘗試。

將請(qǐng)求傳遞到下一個(gè)服務(wù)器可能會(huì)受到 嘗試次數(shù) 和時(shí)間的限制。

句法: proxy_next_upstream_timeout time;
默認(rèn):
proxy_next_upstream_timeout 0;
語境: http, server,location
該指令出現(xiàn)在 1.7.5 版中。

限制請(qǐng)求可以傳遞到 下一個(gè)服務(wù)器的時(shí)間。該0值關(guān)閉此限制。

句法: proxy_next_upstream_tries number;
默認(rèn):
proxy_next_upstream_tries 0;
語境: http, server,location
該指令出現(xiàn)在 1.7.5 版中。

限制將請(qǐng)求傳遞到下一個(gè)服務(wù)器的可能嘗試次數(shù) 。該0值關(guān)閉此限制。

2min是超過了默認(rèn)60s的,所以會(huì)報(bào)504

根據(jù)業(yè)務(wù)量設(shè)置:

相關(guān)upstream配置
proxy_send_timeout 500;
proxy_read_timeout 480;

nginx中文文檔:
1、https://www.nginx.cn/doc/
2、https://www.nginx.cn/nginx-how-to
nginx官網(wǎng)文檔:
1、http://nginx.org/en/docs/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容