본문 바로가기

프로젝트 설정/기타

[ngrok] ngrok이란? (feat. Webhook 테스트 하기)

반응형

1. ngrok이란?

ngrok은 로컬에서 실행 중인 서버를 외부에서 접근 가능하게 해주는 터널링 도구입니다.

인터넷에서 접근 가능한 주소(URL)를 생성하여 로컬 호스트를 외부에 노출시킬 수 있습니다.


2. ngrok의 사용하는 예시

1) 로컬 서버 외부 공개

  • 로컬에서 개발 중인 웹사이트를 외부 사용자에게 공유하고자 할 때 사용됩니다.

2) Webhook 테스트

  • Stripe, GitHub, Slack 등에서 로컬로 이벤트를 받아야 할 때 외부 접속용 주소로 활용합니다.

3) 모바일 앱 로컬 서버 접근

  • 앱이 로컬 서버의 데이터를 사용해야 할 경우, ngrok을 통해 쉽게 접근 가능하게 할 수 있습니다.

4) 원격 디버깅/테스트

  • QA나 클라이언트가 로컬 서버를 직접 테스트할 수 있도록 주소를 공유할 수 있습니다.

5) 단기 외부 노출

  • 임시로 외부 접속을 허용해야 할 때 간편하게 사용할 수 있습니다.

3. Windows에서 ngrok 설치

3.1 다운로드

1) ngrok 다운로드 및 설치

  1. ngrok 공식 웹사이트 접속
  2. 회원가입 및 로그인
  3. Windows용 ngrok 다운로드 후 압축 해제
  4. ngrok.exe 파일을 원하는 폴더에 배치 (예: C:\ngrok)

2) 환경 변수 설정 (선택)

  • 시스템 Path 환경 변수에 ngrok 경로를 추가하면 어느 위치에서든 명령어 사용 가능

3.2 명령어로 설치

install (cmd 관리자 버전 실행)

choco install ngrok -y

 

install 전문

더보기
choco install ngrok
Chocolatey v2.3.0
Installing the following packages:
ngrok
By installing, you accept licenses for the packages.
Downloading package from source 'https://community.chocolatey.org/api/v2/'

ngrok v3.22.1
ngrok package files install completed. Performing other installation steps.
The package ngrok wants to run 'chocolateyinstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Downloading ngrok 64 bit
  from 'https://bin.equinox.io/a/9ehA2XFs1ZK/ngrok-v3-3.22.1-windows-amd64.zip'
Progress: 100% - Completed download of C:\Users\test\AppData\Local\Temp\chocolatey\ngrok\3.22.1\ngrok-v3-3.22.1-windows-amd64.zip (9.28 MB).
Download of ngrok-v3-3.22.1-windows-amd64.zip (9.28 MB) completed.
Hashes match.
Extracting C:\Users\test\AppData\Local\Temp\chocolatey\ngrok\3.22.1\ngrok-v3-3.22.1-windows-amd64.zip to C:\ProgramData\chocolatey\lib\ngrok\tools...
C:\ProgramData\chocolatey\lib\ngrok\tools
 ShimGen has successfully created a shim for ngrok.exe
 The install of ngrok was successful.
  Deployed to 'C:\ProgramData\chocolatey\lib\ngrok\tools'

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).



cmd 관리자 버전으로 실행 안했을 경우 아래와 같이 안됨

더보기
choco install ngrok
Chocolatey v2.3.0
Chocolatey detected you are not running from an elevated command shell
 (cmd/powershell).

 You may experience errors - many functions/packages
 require admin rights. Only advanced users should run choco w/out an
 elevated shell. When you open the command shell, you should ensure
 that you do so with "Run as Administrator" selected. If you are
 attempting to use Chocolatey in a non-administrator setting, you
 must select a different location other than the default install
 location. See
 https://docs.chocolatey.org/en-us/choco/setup#non-administrative-install
 for details.


 Do you want to continue?([Y]es/[N]o): Y

 

설치 확인

ngrok version
ngrok version 3.22.1

choco list --local-only | findstr ngrok # 된다는데 나는 안됨

4. Authtoken 설정

  1. ngrok Dashboard에서 Your Authtoken 복사
  2. 명령 프롬프트(cmd)에서 다음 명령어 실행:
ngrok config add-authtoken [your_authtoken]
ngrok config add-authtoken 2w4fB...
Authtoken saved to configuration file: C:\Users\test\AppData\Local/ngrok/ngrok.yml

5. 로컬 서버 터널링

  • 예: 8000번 포트로 로컬 서버 실행 중이라면
ngrok http 8000
ngrok http http://localhost:8000

6. 기타 명령어

  • 서브도메인 지정 (유료):
ngrok http -subdomain=myproject 8000
  • 설정 파일 사용:
# ~/.ngrok2/ngrok.yml
authtoken: [your_authtoken]
tunnels:
  web:
    proto: http
    addr: 8000
ngrok start --all

7. 주의사항

  • 무료 버전은 URL이 매 실행마다 변경됨
  • 민감한 서버 정보가 노출되지 않도록 접근 제어 필수
  • 장기적인 사용 목적이라면 유료 플랜 고려 필요
반응형

'프로젝트 설정 > 기타' 카테고리의 다른 글

[FTP] FTP 서버 연결하기 (client)  (0) 2022.12.09
[iOS] Xcode12 Build Error  (0) 2022.06.30
[redis] windows redis 설치  (0) 2022.06.07
[Docker] Docker 사용기 (python)  (0) 2021.12.01
[NGINX] 꿀 사이트  (0) 2021.10.22