質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Q&A

3回答

1376閲覧

http://localhost:3000「このページは動作していません」

Gr.

総合スコア89

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

0グッド

1クリップ

投稿2019/05/27 01:42

編集2019/05/27 09:33

rails sを入力すると以下のように出ます。

vagrant@ubuntu-bionic:/vagrant/sample$ rails s => Booting Puma => Rails 5.2.3 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.12.1 (ruby 2.5.5-p157), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Use Ctrl-C to stop

この状態で Google Chrome で localhost:3000 にアクセスすると

このページは動作していません

localhost からデータが送信されませんでした。

となります。

rails s -b 0.0.0.0とすると、問題なく接続できます

ps ax | grep railsps aux | grep pumaを見てみても、別に多重起動している様子もありません。

この場合、rails sで繋げない理由は何が考えられますか?

Vagrantfile

1# -*- mode: ruby -*- 2# vi: set ft=ruby : 3 4# All Vagrant configuration is done below. The "2" in Vagrant.configure 5# configures the configuration version (we support older styles for 6# backwards compatibility). Please don't change it unless you know what 7# you're doing. 8Vagrant.configure(2) do |config| 9 # The most common configuration options are documented and commented below. 10 # For a complete reference, please see the online documentation at 11 # https://docs.vagrantup.com. 12 13 # Every Vagrant development environment requires a box. You can search for 14 # boxes at https://atlas.hashicorp.com/search. 15 config.vm.box = "ubuntu/bionic64" 16 # Disable automatic box update checking. If you disable this, then 17 # boxes will only be checked for updates when the user runs 18 # `vagrant box outdated`. This is not recommended. 19 # config.vm.box_check_update = false 20 21 # Create a forwarded port mapping which allows access to a specific port 22 # within the machine from a port on the host machine. In the example below, 23 # accessing "localhost:8080" will access port 80 on the guest machine. 24 config.vm.network "forwarded_port", guest: 3000, host: 3000 25 26 # Create a private network, which allows host-only access to the machine 27 # using a specific IP. 28 config.vm.network "private_network", ip: "192.168.33.10" 29 30 # Create a public network, which generally matched to bridged network. 31 # Bridged networks make the machine appear as another physical device on 32 # your network. 33 # config.vm.network "public_network" 34 35 # Share an additional folder to the guest VM. The first argument is 36 # the path on the host to the actual folder. The second argument is 37 # the path on the guest to mount the folder. And the optional third 38 # argument is a set of non-required options. 39 40 41 # Provider-specific configuration so you can fine-tune various 42 # backing providers for Vagrant. These expose provider-specific options. 43 # Example for VirtualBox: 44 # 45 # config.vm.provider "virtualbox" do |vb| 46 # # Display the VirtualBox GUI when booting the machine 47 # vb.gui = true 48 # 49 # # Customize the amount of memory on the VM: 50 # vb.memory = "1024" 51 # end 52 # 53 # View the documentation for the provider you are using for more 54 # information on available options. 55 56 # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies 57 # such as FTP and Heroku are also available. See the documentation at 58 # https://docs.vagrantup.com/v2/push/atlas.html for more information. 59 # config.push.define "atlas" do |push| 60 # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" 61 # end 62 63 # Enable provisioning with a shell script. Additional provisioners such as 64 # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the 65 # documentation for more information about their specific syntax and use. 66 config.vm.provision "shell", inline: <<-SHELLSC 67 function install { 68 echo installing $1 69 shift 70 apt-get -y install "$@" >/dev/null 2>&1 71 } 72 73 echo updating package information 74 apt-add-repository -y ppa:brightbox/ruby-ng >/dev/null 2>&1 75 apt-get -y update >/dev/null 2>&1 76 77 install 'development tools' build-essential 78 79 install Ruby ruby2.5 ruby2.5-dev 80 update-alternatives --set ruby /usr/bin/ruby2.3 >/dev/null 2>&1 81 update-alternatives --set gem /usr/bin/gem2.3 >/dev/null 2>&1 82 echo installing Bundler 83 echo "gem: --no-ri --no-rdoc" > ~/.gemrc 84 gem install bundler -N >/dev/null 2>&1 85 install Git git 86 install SQLite sqlite3 libsqlite3-dev 87 install 'Nokogiri dependencies' libxml2 libxml2-dev libxslt1-dev zlib1g-dev 88 install 'ExecJS runtime' nodejs 89 echo 'Installing rails' 90 gem install rails 91 gem install railties 92 gem install listen 93 gem install puma 94 gem install sass 95 gem install tilt 96 gem install spring 97 gem install byebug 98 gem install chromedriver-helper 99 gem install sqlite3 100 gem install rest-client 101 update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 102 echo 'You are now on Rails!' 103 echo ' o o o o o o o . . . ______________________________ _____=======_||____' 104 echo ' o _____ | | | |' 105 echo ' .][__n_n_|DD[ ====_____ | | | |' 106 echo ' >(________|__|_[_________]_|____________________________|_|_________________|' 107 echo ' _/oo OOOOO oo` ooo ooo `o!o!o o!o!o` `o!o o!o` ' 108 echo ' -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-' 109 SHELLSC 110end

追記

rails s -b 0.0.0.0と打てば問題なくつながると書きましたが、この方法でつないだ時はターミナルは以下のようになります。

vagrant@ubuntu-bionic:/vagrant/sample$ rails s -b 0.0.0.0 => Booting Puma => Rails 5.2.3 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.12.1 (ruby 2.5.5-p157), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Use Ctrl-C to stop Started GET "/" for 10.0.2.2 at 2019-05-27 09:19:28 +0000 Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by Rails::WelcomeController#index as HTML Rendering /var/lib/gems/2.5.0/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb Rendered /var/lib/gems/2.5.0/gems/railties-5.2.3/lib/rails/templates/rails/welcome/index.html.erb (4.2ms) Completed 200 OK in 22ms (Views: 8.9ms | ActiveRecord: 0.0ms)

このうち

Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255

の部分が気になったので調べてみて、config/application.rbwhitelistを追加したら上記のメッセージは消えましたが、依然として-b 0.0.0.0を付けないrails sでは http://localhost:3000 に繋げませんので今は戻しています。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2019/05/27 05:49

ゲスト側 OS で、rails を localhost:3000 で起動したということですが、Google Chrome は、ホスト側OS と ゲスト側 OS のどちら側で動かしているのでしょうか?
Gr.

2019/05/27 08:50

CHERRYさん ホスト側OSです。
guest

回答3

0

-b をつけない場合は、 localhost 127.0.0.0 からのアクセスのみとなります。アクセスに使ったchromはvagrant上で動いていないのでアクセス出来ないわけです。

使っている環境はインターネットからアクセス可能な状態ですか?仮にそうであっても3000が開いているとは考えにくいし、vagrantのIPはプライベートアドレスなんでアクセスされません。
それでも心配でしたら。0.0.0.0 ではなく、vagrantとhostマシンをつないでいるsubnet 192.168.33.0 を指定すれば大丈夫です
-b 192.168.33.0

投稿2019/06/04 14:06

winterboum

総合スコア23329

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Gr.

2019/06/05 00:36

winterboumさん 回答ありがとうございます。 今までは rails s だけで普通にアクセスできていたのですが、そのアプリをデプロイして新しくアプリを作り始めたら、新しいアプリでは -b 0.0.0.0 を付けないと local host:3000 にアクセスできなくなりました。デプロイしたアプリの開発環境から特に環境は変えていないので、なぜ2つ目だとダメなのかわかりません。 -b は使ったことがなかったのですが、今作ってるアプリでは毎回付けないとなぜか開けないので、原因と解決策を知りたいです。 rails s -b 192.168.33.0 では rails s と同様にアクセスできませんでした。
guest

0

vagrant使ったことないので、わかりませんが

rails s -b 0.0.0.0とすると、問題なく接続できます。

これで合っていると思いるようですよ。

https://qiita.com/Ago0727/items/325df5e39e3406fa16d2

投稿2019/05/30 00:49

odyu

総合スコア548

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Gr.

2019/05/30 02:00

odyuさん 回答ありがとうございます。 「合っている」ということでひとまず安心させていただきました。 以下、補足になりますが、 質問の件は2つ目のアプリの作成開始段階でおこりました。1つ目を作っていた今まではrails sだけで普通にアクセスできていました。環境的には1つ目をデプロイしたこと以外で特に大きな変更は加えていないのですが、なぜか2つ目のアプリではrails s -b 0.0.0.0でないと繋げなくなってしまいました。 -b 0.0.0.0 指定だと全てから受け入れる設定のようなので、結果として問題なく繋げはするのですが、外部アクセスが可能になるためセキュリティ的に問題があるのかな?なんて思っていて、解決したかったのでここで質問させていただいています。
guest

0

config.vm.network "private_network", ip: "192.168.33.10"

こちらが原因かと思います。

投稿2019/05/27 01:50

編集2019/05/27 01:50
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Gr.

2019/05/27 03:08

10tm84さん > config.vm.network "private_network", ip: "192.168.33.10" こちらの何が原因なのでしょうか。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問