Docker로 여러 개의 Ghost 컨테이너를 실행할 때 Nginx 리버스 프록시(reverse proxy) 를 설정하는 방법을 자세히 설명해 드릴게요.
1. Nginx 리버스 프록시 설정하기
Docker 컨테이너에서 여러 개의 Ghost 인스턴스를 실행하면 각각 다른 포트(port) 를 사용하게 됩니다. 이때, Nginx를 이용해 도메인별로 트래픽을 컨테이너로 전달하도록 설정할 수 있습니다.
💡 예제 시나리오
site1.com→ghost1컨테이너 (포트3001)site2.com→ghost2컨테이너 (포트3002)
2. Ghost 컨테이너 실행하기
Ghost 컨테이너를 각각 다른 포트로 실행합니다.
# Docker 네트워크 생성 (한번만 실행)
docker network create ghost-network
# 첫 번째 Ghost 컨테이너 실행 (site1.com)
docker run -d --name ghost1 \
--network ghost-network \
-e url=http://site1.com \
-p 3001:2368 \
-v /var/lib/ghost1/content:/var/lib/ghost/content \
ghost
# 두 번째 Ghost 컨테이너 실행 (site2.com)
docker run -d --name ghost2 \
--network ghost-network \
-e url=http://site2.com \
-p 3002:2368 \
-v /var/lib/ghost2/content:/var/lib/ghost/content \
ghost
Ghost 컨테이너가 정상적으로 실행되면,
http://localhost:3001→ghost1http://localhost:3002→ghost2에서 Ghost 블로그가 동작합니다.
3. Nginx 리버스 프록시 설정
이제 Nginx가 도메인별로 컨테이너로 요청을 전달하도록 설정합니다.
(1) Nginx 설치 (필요할 경우)
sudo apt update && sudo apt install nginx -y
(2) Nginx 설정 파일 생성
각 도메인별로 server 블록을 설정해야 합니다.
아래 설정 파일을 /etc/nginx/sites-available/ghost로 저장하세요.
server {
listen 80;
server_name site1.com;
location / {
proxy_pass http://localhost:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
server_name site2.com;
location / {
proxy_pass http://localhost:3002;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
(3) 설정 활성화
- 설정을 Nginx 활성화 폴더로 링크합니다.
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ - Nginx 설정을 확인합니다.
sudo nginx -t - Nginx를 다시 시작합니다.
sudo systemctl restart nginx
4. Let’s Encrypt SSL 인증서 추가 (HTTPS 활성화)
만약 HTTPS(SSL 인증서) 를 적용하고 싶다면 Let’s Encrypt + Certbot을 사용할 수 있습니다.
(1) Certbot 설치
sudo apt install certbot python3-certbot-nginx -y
(2) SSL 인증서 발급
sudo certbot --nginx -d site1.com -d site2.com
인증서가 발급되면, Nginx 설정이 자동으로 업데이트되며 HTTPS가 활성화됩니다.
이제 https://site1.com 및 https://site2.com에서 사이트를 사용할 수 있습니다. 🎉
5. Traefik 사용 (고급 방법)
Nginx 대신 Traefik을 이용하면 자동 SSL 및 도메인 관리가 더욱 쉬워집니다.
이 방법이 필요하면 알려주세요!
🔹 정리
✅ Docker로 여러 Ghost 컨테이너를 실행 (각기 다른 포트)
✅ Nginx를 리버스 프록시로 설정하여 도메인별로 트래픽 전달
✅ 필요하면 Let’s Encrypt로 HTTPS 설정
이제 한 서버에서 여러 Ghost 사이트를 운영할 수 있습니다! 🚀