728x90
목적
서버를 외부에 노출하지 않고도 Cloudflare를 통해 안전하게 접속할 수 있도록 Cloudflare Tunnel을 설정한다.
설치 및 기본 설정
Cloudflare 저장소 및 GPG 키 등록
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
패키지 소스 등록 & cloudflared 설치
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get update && sudo apt-get install cloudflared
Cloudflare 로그인 및 터널 생성
Cloudflare 계정 인증 → 인증 링크 클릭해서 Cloudflare 계정에 연결
cloudflared tunnel login
터널 생성
→ 터널 생성 시 <Tunnel-ID>
가 출력됨
→ 인증 파일이 자동으로 /home/<사용자명>/.cloudflared/<Tunnel-ID>.json
에 저장됨
cloudflared tunnel create my-tunnel
구성 파일 설정
구성 파일 작성
경로: /etc/cloudflared/config.yml
tunnel: <Tunnel-ID>
credentials-file: /home/taecheonin/.cloudflared/<Tunnel-ID>.json
터널 실행
터널 실행 (수동)
cloudflared tunnel run my-tunnel
재부팅 시 자동 실행 설정
서비스 설치 및 활성화
sudo cloudflared service install
sudo systemctl enable cloudflared
sudo systemctl start cloudflared
sudo systemctl status cloudflared
도메인 인그레스 설정 (옵션)
/etc/cloudflared/config.yml
에 다음 블록 추가:
단일 호스트 설정 예시:
ingress:
- hostname: leeyounghun.com
service: http://localhost:8000
- service: http_status:404
여러 도메인 처리 예시:
ingress:
- hostname: example.com
service: http://localhost:3000
- hostname: www.example.com
service: http://localhost:3000
- service: http_status:404
기억할 점
Tunnel-ID
와.json
인증 파일은 절대 유출 금지config.yml
경로는/etc/cloudflared/
- 자동 실행을 위해
cloudflared service install
필수 - ingress 설정은 도메인 → 내부 서비스 매핑
필요하면 systemctl status cloudflared
로 상태 확인 가능!
728x90
'소개 > 소소한공부' 카테고리의 다른 글
FastAPI로 "Hello, World!" 만들고 서버 재시작해도 자동 실행되게 하기! (1) | 2025.04.11 |
---|---|
개발환경에서 로컬 서버 외부에 노출하는 방법 모음 (1) | 2025.04.11 |
30대의 성공적인 이직 전략 라이프 스테이지에 맞는 기업 선택의 비밀 (2) | 2025.04.10 |
Lubuntu 구형 컴퓨터를 살리는 초경량 리눅스 배포판 (2) | 2025.04.09 |
SMTP 이메일 전송 서비스들의 무료 요금제 비교 (3) | 2025.04.08 |