리버스 프록시 - Caddy 설정
이 문서는 Docker Compose를 사용해 Jenkins를 Caddy 뒤에서 HTTPS 리버스 프록시로 구성하는 방법을 보여줘요. 핵심은 Caddy가 도메인에 대한 HTTPS 요청을 받아 내부의 Jenkins 컨테이너(8080 포트)로 전달하는 구조예요. 서브도메인 방식과 서브경로(/jenkins) 방식 두 가지를 모두 다룹니다.
출처: Jenkins 문서
본문
사전 요구 사항 (Prerequisites)
- 도메인의 DNS가 Docker 호스트를 가리키도록 설정되어 있어야 합니다.
- 80/443 포트가 인터넷에 열려 있어야 합니다.
- (선택 사항, 서브경로용) Jenkins 컨텍스트 경로(예:
/jenkins)를 정합니다.
파일
같은 디렉터리에 다음 두 파일을 만드세요.
docker-compose.yml
version: "3.9"
services:
jenkins:
image: jenkins/jenkins:lts-jdk25
container_name: jenkins
restart: unless-stopped
# If you want Jenkins on a sub-path like /jenkins, uncomment the next line
# environment:
# - JENKINS_OPTS=--prefix=/jenkins
volumes:
- jenkins_home:/var/jenkins_home
expose:
- "8080" # internal to the compose network
# - "50000" # optional: classic JNLP agents (WebSocket usually removes the need)
networks:
- web
caddy:
image: caddy:2
container_name: caddy
restart: unless-stopped
depends_on:
- jenkins
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- web
networks:
web:
driver: bridge
volumes:
jenkins_home:
caddy_data:
caddy_config:
Caddyfile (서브도메인)
# Replace with your real domain
jenkins.example.com {
encode zstd gzip
reverse_proxy jenkins:8080
}
Caddyfile (서브경로 /jenkins)
# Replace with your real domain
example.com {
encode zstd gzip
@jenkins path /jenkins*
handle @jenkins {
handle_path /jenkins* {
reverse_proxy jenkins:8080
}
}
}
실행
docker compose up -d
Jenkins URL
시작 후 Manage Jenkins → System → Jenkins Location에서 Jenkins URL을 다음 중 하나로 설정하세요.
https://jenkins.example.com/(서브도메인)https://example.com/jenkins/(서브경로; 위 예시처럼JENKINS_OPTS=--prefix=/jenkins가 설정되어 있는지 확인하세요)
더 알아보기 (Learn more)
리버스 프록시 설정과 관련한 다른 구성 방법 및 자주 겪는 문제는 리버스 프록시 구성 및 리버스 프록시 문제 해결 문서를 참고하세요.