Cloudflare Tunnel이란?
Cloudflare Tunnel(cloudflared)은 로컬에서 실행 중인 서비스를 외부에 안전하게 노출시켜주는 도구
설치
macOS
Homebrew를 사용한 설치 방법입니다.
# cloudflared 설치
brew install cloudflared
# 설치 확인
cloudflared --version
기본 사용법
1. 빠른 테스트 (임시 터널)
가장 간단한 방법으로, 인증 없이 바로 사용할 수 있습니다:
# localhost:3000을 외부에 노출
cloudflared tunnel --url http://localhost:3000
실행하면 다음과 같은 출력이 나타납니다:
+----------------------------------------------------------------------------+
| Your quick Tunnel has been created! Visit it at (it may take some time to be reachable): |
| https://random-words-1234.trycloudflare.com |
+----------------------------------------------------------------------------+
이 URL을 통해 외부에서 접근할 수 있습니다.
2. 영구 터널 생성 (권장)
더 안정적이고 영구적인 터널을 생성하려면:
1단계: Cloudflare 계정 로그인
# 브라우저에서 로그인
cloudflared tunnel login
이 명령어를 실행하면 브라우저가 열리고 Cloudflare 계정으로 로그인합니다.
2단계: 터널 생성
# 터널 생성 (이름은 원하는 대로 지정)
cloudflared tunnel create my-tunnel
3단계: 라우팅 설정
Cloudflare 대시보드에서 도메인을 설정하거나, 명령어로 설정할 수 있습니다:
# 도메인에 라우팅 설정
cloudflared tunnel route dns my-tunnel example.com
4단계: 설정 파일 생성
# 설정 파일 생성
cloudflared tunnel create my-tunnel
설정 파일 위치: ~/.cloudflared/config.yml
tunnel: <tunnel-id>
credentials-file: /Users/username/.cloudflared/<tunnel-id>.json
ingress:
- hostname: example.com
service: http://localhost:3000
- service: http_status:404
5단계: 터널 실행
# 터널 실행
cloudflared tunnel run my-tunnel
또는 설정 파일을 지정하여:
cloudflared tunnel --config ~/.cloudflared/config.yml run
실전 예제
웹 개발 서버 노출
# Next.js 개발 서버 (포트 3000)
cloudflared tunnel --url http://localhost:3000
# React 개발 서버 (포트 3001)
cloudflared tunnel --url http://localhost:3001
# Express 서버 (포트 5000)
cloudflared tunnel --url http://localhost:5000
API 서버 노출
# REST API 서버 (포트 8000)
cloudflared tunnel --url http://localhost:8000
여러 서비스 동시 노출
설정 파일을 사용하여 여러 서비스를 동시에 노출할 수 있습니다:
tunnel: my-tunnel
credentials-file: /Users/username/.cloudflared/<tunnel-id>.json
ingress:
- hostname: api.example.com
service: http://localhost:8000
- hostname: web.example.com
service: http://localhost:3000
- service: http_status:404
주요 명령어
# 터널 목록 확인
cloudflared tunnel list
# 터널 정보 확인
cloudflared tunnel info my-tunnel
# 터널 삭제
cloudflared tunnel delete my-tunnel
# 터널 실행 (백그라운드)
cloudflared tunnel run my-tunnel &