ngrok은 외부에서 방화벽을 넘어 localhost에 접속할 수 있도록 해주는 프로그램이다.


ngrok 웹 페이지에서 zip 파일 다운 받아 압축 풀면 바로 사용할 수 있다.


우선, ngrok 웹 페이지에 가서 회원가입을 하면 authtoken을 부여 받는다. 링크를 통해 확인 가능하다.


다음 명령어를 통해 부여 받은 token으로 설정해준다.

./ngrok authtoken 1q2w3e4r


일반적으로 http command와 port를 입력하면 http://localhost:80에 mapping시켜준다.

./ngrok http 80


ngrok을 실행하면 다음과 같이 나오고 url을 통해 외부에서 접속할 수 있다.

Session Status                online
Account                       ***** (Plan: Free)
Version                       2.3.40
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://356b-175-212-255-58.ngrok.io -> http://localhost:80
Forwarding                    https://356b-175-212-255-58.ngrok.io -> http://localhost:80
Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00


그리고 http://localhost:4040로 ngrok의 web inspector가 같이 실행된다.


https://localhost:8081에 mapping시키려면 다음과 같이 실행하면 된다.

./ngrok http https://localhost:8081 --host-header="localhost:8081"


ngrok docker 이미지도 존재한다.


다음과 같이 docker 이미지를 실행할 수 있다.

docker run -it --p 4040:4040 ngrok/ngrok http 80


하지만 다음과 같이 명령어를 실행하여 주어지는 url로 접속해봤는데 502 Bad Gateway가 떴다.

docker run -it -p 4040:4040 -p 8081:8081 \
-e NGROK_AUTHTOKEN=1q2e3e4r \
ngrok/ngrok http https://localhost:8081 --host-header="localhost:8081"


docker를 통해 https를 mapping시키는 것은 안 되는 듯 하다.