LoginSignup
17
19

More than 3 years have passed since last update.

【Rails】ローカル開発環境で、別の端末からrails serverにWEBアクセスする方法

Last updated at Posted at 2019-04-17

前提

説明のため前提として、サーバーPCとクライアントPCは同じWi-Fi(同一SSID)に
接続しているものとします。
また、Wi-Fiルーターの設定が「LAN内の通信許可」されているとします。

サーバーPCのIPアドレス確認

ターミナルでifconfig コマンドを入力して、wi-fiで接続しているインターフェイスのIPアドレスを確認する。

$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
XHC0: flags=0<> mtu 0
XHC20: flags=0<> mtu 0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether xxxxxxxxxxxxxxxxxxx
    inet6 fe80::a5:5017:3c48:df62%en0 prefixlen 64 secured scopeid 0x6 
    inet 192.168.11.10 netmask 0xffffff00 broadcast 192.168.11.255
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active

en0: を見ると 192.168.11.10 であるのが分かる。

serverを立ち上げる。

サーバーPCでrails serverを立ち上げます。この時-b オプションが必要。

rails s -b 0.0.0.0

別の端末からWEBアクセス

rails s したPCと同じWi-Fi(同一のSSID)に接続し、
ブラウザのアドレスバーにサーバーPCのIPアドレス3000番ポート番号を指定して入力する。
今回の場合、サーバーPCのIPアドレスが192.168.11.10なので、192.168.11.10:3000
と入力する。

スクリーンショット 2019-04-17 22.00.18.png

これでherokuなどにデプロイしなくても、スマホから画面確認などが出来ます。
また、httpなのでwiresharkなどでパケットキャプチャーすれば中身が見れます。

17
19
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
17
19