배경
지금까지는 한 대의 서버로 개발하였지만 대규모 트래픽에서는 한 대의 서버로는 부족
그래서 서버를 3대로 늘리고 nginx를 사용해 트래픽을 분산하는 아키텍처 구축
설계
- Docker Compose: 똑같은 기능을 하는 Spring Boot 서버를 3개 복제
- Nginx (Load Balancer): 클라이언트의 요청을 받아 3개의 서버 중 하나로 전달, 이때 기본설정인 라운드 로빈(Round Robin) 알고리즘을 사용하여 순서대로 공평하게 분배
docker-compose.yml
app:
build: .
deploy:
replicas: 3
environment:
SERVER_PORT: 8000
Nginx 로드밸런서 설정
nginx를 사용하는 이유 : Apache 같은 스레드 기반 서버와 달리, Nginx는 비동기 이벤트 기반 구조를 가짐
적은 메모리로 대량의 동시 접속을 처리할 수 있어, 수만 개의 요청이 몰리는 로드 밸런서 역할에 최적화
nignx.conf
events {}
http {
upstream backend {
# Docker's internal DNS will resolve 'app' to ALL container IP addresses
# that belong to the 'app' service. Nginx will then Round Robin between them.
server app:8000;
}
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
트러블 슈팅 🔥 : nginx 설정과 spring boot 기본설정이 달라 포트가 달랐던 문제가 생김
확인: 새로고침마다 서버가 바뀌는 것을 확인
[Feat] Nginx 로드밸런싱 도입 및 Docker Compose 기반 분산 환경 구축 by 0hj1hyeon · Pull Request #13 · 0hj1hyeon
로컬 개발 환경을 docker run 방식에서 Docker Compose 기반으로 전환했습니다. Nginx를 도입하여 Load Balancing(Round Robin) 환경을 구축했습니다. Spring Boot 애플리케이션을 3개의 인스턴스(Replicas)로 확장하여
github.com
'분산 처리 환경' 카테고리의 다른 글
| 스프링 분산 처리 환경 16: Config Server (0) | 2026.01.23 |
|---|---|
| 스프링 분산 처리 환경 15: MSA (0) | 2026.01.15 |
| 스프링 분산 처리 환경 13: Docker Compose (0) | 2025.12.19 |
| 스프링 분산 처리 환경 12: Kubernetes (0) | 2025.12.18 |
| 스프링 분산 처리 환경 11: Docker (0) | 2025.12.14 |