Closed4
Nginxエラー対応ログ
![a](https://res.cloudinary.com/zenn/image/fetch/s--3G1s_H9y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/8e2699e069.jpeg)
Nginxでコネクションが閉じてしまうとき[502エラー]
以下のようなエラーが頻発する
# ERROR message
upstream prematurely closed connection while reading response header from upstream, client: xxx, server: xxx, request: "GET xxx HTTP/1.1", upstream: "xxx", host: "xxx"
connect() failed (111: Connection refused) while connecting to upstream, client: xxx, server: xxx, request: "GET xxx", upstream: "xxx", host: "xxx"
# 意味
upstreamからレスポンスヘッダを読み込んでる最中にコネクションがクローズしたよ
upstreamに接続しようとしたときにコネクションが拒否されたよ
![a](https://res.cloudinary.com/zenn/image/fetch/s--3G1s_H9y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/8e2699e069.jpeg)
参考文献
![a](https://res.cloudinary.com/zenn/image/fetch/s--3G1s_H9y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/8e2699e069.jpeg)
原因
コネクションがクローズしたり、拒否される原因は、upstream serverで何かしらの制限に引っかかってしまっているため、クラッシュしたりプロセスが終了していることが考えられる。
制限になるものとして、例えばCPUやメモリ、何かしらの処理実行時間などがあげられる。
![a](https://res.cloudinary.com/zenn/image/fetch/s--3G1s_H9y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/8e2699e069.jpeg)
今回は、ECS on EC2上にコンテナがデプロイされているので、AWSのコンテナインサイトでアプリケーションコンテナのメモリとCPUを確認し、メモリ不足が原因であることが判明した。
または、docker status
でコンテナのCPUやメモリ使用率を見たり、コンテナ内でfree -m
やtop
コマンドで確認すれば良い。
このスクラップは2021/01/18にクローズされました