본문 바로가기

nginx 뒤 스프링부트에서 502가 간헐적으로만 납니다 (upstream prematurely closed connection)

조회 1 · 댓글 0
모나미153모나미153작성자2026년 8월 27일

지난번에 RemoteIpValve로 IP 문제 잡은 그 서버입니다(우분투 24.04, nginx 1.24, 스프링부트 3.4 내장 톰캣). 이번엔 다른 증상인데, 하루에 몇 번씩 502 Bad Gateway가 뜨고 바로 새로고침하면 정상입니다. 부하가 높은 시간대도 아니고 앱 로그에는 에러가 하나도 없습니다.

nginx error.log에는 이 줄만 반복해서 찍힙니다.

upstream prematurely closed connection while reading response header from upstream, client: x.x.x.x, request: "GET /api/... HTTP/2.0", upstream: "http://127.0.0.1:8080/api/..."

location 설정은 이렇게 돼 있습니다. keepalive는 성능 글 보고 따라 넣은 겁니다.

upstream app {
    server 127.0.0.1:8080;
    keepalive 32;
}
location / {
    proxy_pass http://app;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

톰캣이 죽는 것도 아니고 재시작한 적도 없는데 왜 연결이 끊긴다고 하는 건지 모르겠습니다. 어디를 봐야 할까요?

로그인 후 답글을 남길 수 있습니다.