ngrok とは
ngrokとはローカルサーバーをインターネット上へ公開することのできるサービスです。
Web開発の現場では、Webhookのテストによく使われていると思います。
基本的な使い方
http://localhost
のWebサイトを指定する場合であれば、次のように起動します。
ngrok http 80
Homestead を用いた使い方
Hostヘッダを指定することで、Laravel Homestead上のWebサイトを公開することができます。
ngrok http <homestead_host_ip>:<port> -host-header=<homestead_domain>
HomesteadのIPアドレスが 192.168.10.10
で http://homestead.test
のWebサイトを指定する場合であれば、次のように起動します。
ngrok http 192.168.10.10:80 -host-header=homestead.test
ngrok の設定ファイルを使った起動方法
設定ファイルに接続先を定義することで、次のようにコマンドを簡易化することができます。
ngrok start homestead
デフォルトの設定ファイルを上書きする場合は次のファイルを編集してください。
OS X /Users/example/.ngrok2/ngrok.yml
Linux /home/example/.ngrok2/ngrok.yml
Windows C:\Users\example\.ngrok2\ngrok.yml
トンネル名 homestead
と another
を定義する例です。
homestead:
proto: http
addr: 192.168.10.10:80
host_header: homestead.test
another:
proto: http
addr: 192.168.10.10:80
host_header: another.test
ngrok start homestead
と ngrok start another
が使えるようになりました。