ngrok 이란?

ngrok은 로컬 개발 환경에서 실행 중인 서버를 외부에서 접근 가능하도록 해주는 무료 터널링 서비스

 

보통 로컬에서 띄운 서버를 외부에서 접속할 수 있도록 연결해 간단한 테스트를 해볼 때 많이 이용한다.

 

 

ngrok 계정 생성 및 로그인

서버 또는 로컬에 ngrok을 설치하기 전에 ngrok에서 계정이 생성되어 있어야 한다.

아래 홈페이지에서 계정을 생성한다.

https://ngrok.com/

 

ngrok | API Gateway, Kubernetes Ingress, Webhook Gateway

ngrok simplifies app delivery by unifying API gateway, Kubernetes ingress, multi-cluster load balancing and more with ngrok's Universal Gateway.

ngrok.com

 

 

 

ngrok 설치

Linux 환경에서 설치

# ngrok 다운로드
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz

# 압축 해제
tar -xzf ngrok-v3-stable-linux-amd64.tgz

# 실행 파일을 시스템 경로로 이동
sudo mv ngrok /usr/local/bin/

# 실행 권한 부여
sudo chmod +x /usr/local/bin/ngrok

# 설치 확인
ngrok version

 

 

mac os 환경에서 설치

# homebrew 설치
brew install ngrok

 

 

 

ngrok 토큰 추가

 

ngrok 홈페이지에서 토큰을 발급

https://dashboard.ngrok.com/get-started/your-authtoken

 

ngrok — Log in

 

dashboard.ngrok.com

 

 

서버 또는 로컬에 토큰 추가

# ngrok 발급 토큰 추가
ngrok config add-authtoken [my-authtoken]

# 결과 확인
Authtoken saved to configuration file: /root/.config/ngrok/ngrok.yml

 

 

 

ngrok 실행

# HTTP 터널 생성 (포트 3000)
ngrok http 3000

# HTTPS 터널 생성
ngrok http 3000 --scheme https

# 특정 도메인 사용 (유료 계정 필요)
ngrok http 3000 --domain=your-domain.ngrok.io

# 백그라운드에서 실행
nohup ngrok http 3000 > ngrok.log 2>&1 &

# 프로세스 확인
ps aux | grep ngrok

# 로그 확인
tail -f ngrok.log

 

 

ngrok은 http 외에 tcp도 연결이 가능해서 mqtt 통신을 이용할 때 유용하게 사용할 수 있다.

 

`ngrok tcp 1883` 같은 명령어로 간단히 이용할 수 있다.

 

 

 

백그라운드에서 실행한 경우, ngrok 웹페이지 메뉴에서 domain과 port 정보를 확인할 수 있다.

 

https://dashboard.ngrok.com/endpoints

 

ngrok — Log in

 

dashboard.ngrok.com

 

+ Recent posts