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 rails
やps 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.rb
にwhitelist
を追加したら上記のメッセージは消えましたが、依然として-b 0.0.0.0
を付けないrails s
では http://localhost:3000 に繋げませんので今は戻しています。