天天看點

nginx 504 upstream timed out (110: Connection timed out) while reading response header from upstream

今天在做一個功能的時候一直出現nginx504 time-out的問題,具體的錯誤如下(紅色的是主要錯誤資訊)

2018/07/24 19:11:00 [error] 10621#0: *3581841 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 118.116.107.52, server: test.data.main.cn, request: "POST /xdnphb/data/wordCloud/txtFile HTTP/1.1", upstream: "http://127.0.0.1:8090/xdnphb/data/wordCloud/txtFile", host: "test.data.main.cn", referrer: "http://test.data.main.cn/wordCloud.html"

 就是因為伺服器後端相應時間逾時,之前設定的是10秒,但是有一個請求在某些時候需要大概30秒的時間處理資料,是以在nginx.conf的server{}裡面增加如下配置

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 20m;    #允許用戶端請求的最大單檔案位元組數
    client_body_buffer_size 128k;  #緩沖區代理緩沖使用者端請求的最大位元組數,
    proxy_connect_timeout 1 ;  #nginx跟後端伺服器連接配接逾時時間(代理連接配接逾時)
    proxy_send_timeout 10;        #後端伺服器資料回傳時間(代理發送逾時)
    proxy_read_timeout 10;         #連接配接成功後,後端伺服器響應時間(代理接收逾時)
    proxy_buffer_size 4k;             #設定代理伺服器(nginx)儲存使用者頭資訊的緩沖區大小
    proxy_buffers 4 32k;               #proxy_buffers緩沖區,網頁平均在32k以下的話,這樣設定
    proxy_busy_buffers_size 64k;    #高負荷下緩沖大小(proxy_buffers*2)
    proxy_temp_file_write_size 64k;  #設定緩存檔案夾大小,大于這個值,将從upstream伺服器傳
           

主要是修改這兩個參數

proxy_send_timeout 60;        #後端伺服器資料回傳時間(代理發送逾時)
    proxy_read_timeout 60;         #連接配接成功後,後端伺服器響應時間(代理接收逾時)
           

ok,問題解決,沒有出現504 time-out的問題了。

原文連結(我的小站):https://www.wallsay.com/article/A20180724203526267

繼續閱讀