1
1

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 1 year has passed since last update.

【初学者向け】ローカルで動作するRailsアプリを配布なしで外部に公開できる?

Last updated at Posted at 2023-10-19

はじめに

開発プロセスにおいて、しばしば直接の配布せずにローカル環境で動作しているアプリケーションを外部から確認する必要性が出てきます。本記事では、ngrokを用いてローカルで動作しているRailsアプリケーションをパブリックWeb URLで確認する方法を説明します。

手順

1) ngrok会員登録

まず ngrokで無料アカウントを作成し、アカウントの認証トークンを取得します。

Screen Shot 2023-10-15 at 19.16.25.png

2) ngrok設置

OSに応じてngrokクライアントライブラリをダウンロードします。

MacOS
brew install ngrok/ngrok/ngrok
Windows(Chocolatey)
choco install ngrok

他のダウンロード方法は、以下のリンクを参考にしてください。
https://ngrok.com/download

3) ngrokエージェントの連動

ターミナルで以下のコマンドを実行して、1)で取得したngrok認証トークンを設定します。

ngrok config add-authtoken TOKEN

4) ngrok実行

認証トークンが設定されると、ローカルで動作されているアプリケーションのトンネルを開始できるようになります。localhostのポート3443でトンネルを開始するには、以下のコマンドを実行するだけです。

ngrok http 3443
実行結果
ngrok                                                                                                                                                                               (Ctrl+C to quit)
                                                                                                                                                                                                    
Introducing Always-On Global Server Load Balancer: https://ngrok.com/r/gslb                                                                                                                         
                                                                                                                                                                                                    
Session Status                online                                                                                                                                                                
Account                       Ngrok (Plan: Free)                                                                                                                                           
Update                        update available (version 3.3.5, Ctrl-U to update)                                                                                                                    
Version                       3.3.2                                                                                                                                                                 
Region                        Japan (jp)                                                                                                                                                            
Latency                       20ms                                                                                                                                                                  
Web Interface                 http://127.0.0.1:4040                                                                                                                                                 
Forwarding                    https://some_random_domain.ngrok-free.app -> http://localhost:3443                                                                             
                                                                                                                                                                                                    
Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                                           
                              0       0       0.00    0.00    0.00    0.00   

5) RailsにngrokのURL登録

Railsのconfig/environments/development.rbにあるconfig.hostsにngrok実行する時に取得したForwardingのホストネームを入力します。

config.hosts << "some_random_domain.ngrok-free.app"

6) NgrokのForwarding URL接続

NgrokのForwarding URL接続して、ローカルでホストされているRailsアプリを確認します。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?