0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ngrok使ってみた

Last updated at Posted at 2020-11-17

概要

新卒,3回目の投稿です。
ngrokを使う機会があり、非常に便利だと感じたので使い方を書いていきます。
ngrokはlocalhostで立ち上げたサーバに外部からアクセスできるようにするツールです。
今回はGoをでlocalhostを立ち上げ、私物のスマホからlocalhostにアクセスしてみました。

ngrokをインストールする

公式サイトよりユーザー登録をしたら、zipファイルをダウンロードし、解凍します。
ユーザー登録にはgithubまたはgoogleアカウントを使うことができます。
解凍が済んだら、ngrok.exeを起動し、コマンドを打ち込みます。

ngrok http 8080

下記のような表示が見えれば完了です。
localhost:8080に対し、https://66336728576f.ngrok.ioで外部環境からアクセスすることができます。

ngrok by @inconshreveable
(Ctrl+C to quit)
Session Status                online
Version                       2.3.35
Account                       アカウント名 (Plan: Free)
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://66336728576f.ngrok.io -> http://localhost:8080
Forwarding                    https://66336728576f.ngrok.io -> http://localhost:8080
Connections                   ttl     opn     rt1     rt5     p50     p90
0       0       0.00    0.00    0.00    0.00

実際に外部からアクセスしてみる

package main

import (
	"fmt"
	"net/http"
)

func main() {
	http.HandleFunc("/", handler)
	http.ListenAndServe(":8080", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "ngrok超便利")
}

私物のスマホより、https://66336728576f.ngrok.ioにアクセスすると、ngrok超便利が表示されました!
ngrok便利ですね。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?