由nginx和spring boot中tomcat配置不當引起的問題
阿新 • • 發佈:2018-11-22
最近接淺橙貸超Api推過來的流量,由於有幾個請求頭的body體積比較大,最大有30M,到我們這邊nginx的error日誌就報錯了:
2018/11/19 22:33:52 [error] 9791#0: *639124 readv() failed (104: Connection reset by peer) while reading upstream, client: 116.62.210.85, server: axdapi.adpanshi.com, request: "POST /qianchengApi/doCall HTTP/1.1", upstream: "http://127.0.0.1:10030/qianchengApi/doCall", host: "axdapi.adpanshi.com"
然後還有一串警告:
2018/11/22 11:03:40 [warn] 18674#0: *41074 a client request body is buffered to a temporary file /var/lib/nginx/tmp/client_body/0000002187, client: 116.62.210.85, server: axdapi.adpanshi.com, request: "POST /qianchengApi/doCall HTTP/1.1", host: "axdapi.adpanshi.com"
然後在nginx access.log裡也有很多報500錯誤
- 120.55.62.188 - - [19/Nov/2018:19:47:52 +0800] "POST /qianchengApi/doCall HTTP/1.1" 200 138 "-" "SH-XJ360""request_time:1.092" "upstream_response_time:1.092" - 116.62.210.85 - - [19/Nov/2018:19:47:57 +0800] "POST /qianchengApi/doCall HTTP/1.1" 500 25 "-" "SH-XJ360""request_time:3.913" "upstream_response_time:0.015" - 120.55.62.188 - - [19/Nov/2018:19:48:05 +0800] "POST /qianchengApi/doCall HTTP/1.1" 200 87 "-" "SH-XJ360""request_time:0.857" "upstream_response_time:0.857" - 116.62.210.85 - - [19/Nov/2018:19:48:07 +0800] "POST /qianchengApi/doCall HTTP/1.1" 500 25 "-" "SH-XJ360""request_time:2.095" "upstream_response_time:0.012" - 116.62.210.85 - - [19/Nov/2018:19:48:31 +0800] "POST /qianchengApi/doCall HTTP/1.1" 500 25 "-" "SH-XJ360""request_time:1.392" "upstream_response_time:0.013" - 116.62.210.85 - - [19/Nov/2018:19:48:36 +0800] "POST /qianchengApi/doCall HTTP/1.1" 500 25 "-" "SH-XJ360""request_time:1.649" "upstream_response_time:0.012" - 120.55.62.188 - - [19/Nov/2018:19:49:05 +0800] "POST /qianchengApi/doCall HTTP/1.1" 200 211 "-" "SH-XJ360""request_time:0.120" "upstream_response_time:0.120" - 116.62.210.85 - - [19/Nov/2018:19:49:07 +0800] "POST /qianchengApi/doCall HTTP/1.1" 500 25 "-" "SH-XJ360""request_time:1.270" "upstream_response_time:0.012"
當時叫來了運維,把nginx.conf 裡的client_max_body_size調成32m,還改了一些其他連線超時的引數(哪些記不清了),但是錯誤依舊,這時想到報500有可能是應用的問題。然後在core的spring boot的配置檔案里加上了:
server.tomcat.max-http-post-size = 33554432
我記得在middle層加上的是
server.tomcat.max-http-post-size = -1
結果還是不行
然後在Application.java里加了下面程式碼設定最大執行緒和連線數,但結果還是有報錯
protected void customizeConnector(Connector connector) { super.customizeConnector(connector); Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); // 設定最大連線數 protocol.setMaxConnections(2000); // 設定最大執行緒數 protocol.setMaxThreads(2000); protocol.setConnectionTimeout(30000); }
最後在檢查時把middle層的applicationproperties