1. 程式人生 > >graphite報錯:upstream prematurely closed connection while reading response header from upstream

graphite報錯:upstream prematurely closed connection while reading response header from upstream

線上監控系統使用grafana+graphite,graphite使用nginx+uwsgi啟動。有一次在grafana上監控圖出現錯誤,顯示響應式502,於是先檢查graphite-web,發現在graphite-web介面上偶爾打不開。

然後再nginx的error日誌上顯示如下資訊:

2018/09/25 17:05:04 [error] 20967#0: *640 upstream prematurely closed connection while reading response header from upstream, client: 110.39.12.24, server: localhost, request: "POST /render HTTP/1.1", upstream: "uwsgi://127.0.0.1:9090", host: "110.39.12.24"

graphite-web是django寫的,找一篇文章”django upstream prematurely closed connection while reading response header from up“,解決方法如下:

1.必須要在uwsgi.ini中設定“limit-as”,該值是每個uwsgi程序佔用的虛擬記憶體的最大限制。
2.檢查nginx上是否設定了

proxy_http_version 1.1;
proxy_set_header Connection "";

Nginx預設使用HTTP1.0從後端獲取響應返還給客戶端,但是HTTP1.0不支援keepalive,因此需要配置proxy_http_version 1.1,proxy_set_header Connection預設close:通知後端伺服器主動關閉連線,這樣會導致任何一個客戶端的請求都在後端伺服器上產生了一個TIME-WAIT狀態的連線。
3.檢查uwsgi和Nginx中設定的各種timeout是否過短。
 

參考:

https://blog.csdn.net/lj1404536198/article/details/79138379