LoginSignup
107

More than 5 years have passed since last update.

ngrokの使い方(windows, mac)

Posted at

概要

ngrokとは、localhostで動いているサーバーを、LANの外からアクセスできるようにできるツールです。
vagrantなどのローカル環境を一時的に外部に公開できるため、webhookなどの受信が必要なシステムでも、ローカルで動かすことが可能となります。

windows, mac両環境でのインストール手順です。

環境

  • macOS Sierra 10.12.3 / Windows 7, 10
  • ngrok 2.2.4
  • Vagrant 1.9.0

インストール

windowsの場合

  • ここからwindows版ダウンロード
  • ダウンロードしたngrok.zipを任意のフォルダに解凍

macの場合

ホストOSで以下を実行してインストールする。

  • ここでmac版のダウンロードURLを調べて、CURLでダウンロード
[HostOS]$ curl -O https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip
[HostOS]$ unzip ngrok-stable-darwin-amd64.zip

Vagrantfileを編集

ホストOSに対する8888ポートへのアクセスを、ゲストOSの80ポートに転送する。

Vagrantfile

Vagrantfile
config.vm.network :forwarded_port, host: 8888, guest: 80

Vagrantfile再起動

[HostOS]$ vagrant reload

ngrokを起動

ngrokをダウンロードしたディレクトリに移動して、下記コマンドで起動。
windowsの場合はコマンドプロンプトなどで、macの場合はterminalなどで実行。

windowsの場合

[HostOS]$ ngrok http 8888

macの場合

[HostOS]$ ./ngrok http 8888
EXAMPLES:
    ngrok http 80                    # secure public URL for port 80 web server
ngrok by @inconshreveable                                                                                                                                           (Ctrl+C to quit)

Session Status                online
Version                       2.2.4
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://xxxxxxxx.ngrok.io -> localhost:8888
Forwarding                    https://xxxxxxxx.ngrok.io -> localhost:8888

Connections                   ttl     opn     rt1     rt5     p50     p90
                              6       0       0.05    0.02    23.33   25.98

これで、ブラウザからhttp://xxxxxxxx.ngrok.io へアクセスすると、vagrantの80番ポートにアクセスが可能となります。
また、ngrokのアドレスは、起動するたびに変わります。

以上

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
107