2017-02-25 104 views
-1

我目前在我的Mac OS上安装了Debian虚拟机,在其中安装了Ruby 2.4.0。我使用VirtualBox和流浪在虚拟机上托管一个rails服务器

首先,我无法启动我的服务器这样rails server,因为当我尝试访问它在我的Mac OS的Web浏览器,我有这样的错误:

The localhost page isn’t working 

localhost didn’t send any data. 

所以,我要推出这样说:rails server -b 0.0.0.0我不知道为什么我无法启动它127.0.0.1(默认IP)

而且,这里是我有当消息我是l开始我的Rails服务器。

/usr/local/lib/ruby/gems/2.4.0/gems/activesupport- 

5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated 
/usr/local/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated 
=> Booting Puma 
=> Rails 5.0.1 application starting in development on http://0.0.0.0:3000 
=> Run `rails server -h` for more startup options 
/usr/local/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated 
Puma starting in single mode... 
* Version 3.7.1 (ruby 2.4.0-p0), codename: Snowy Sagebrush 
* Min threads: 5, max threads: 5 
* Environment: development 
* Listening on tcp://0.0.0.0:3000 

虽然我知道,过时的东西警告相关的事实,我使用Ruby的最新版本,我不明白,最后5行:

Puma starting in single mode... 
* Version 3.7.1 (ruby 2.4.0-p0), codename: Snowy Sagebrush 
* Min threads: 5, max threads: 5 
* Environment: development 
* Listening on tcp://0.0.0.0:3000 

你能向我解释这些的含义?

最后但并非最不重要,当我去http://0.0.0.0:3000,即使我有正确的显示(Yay!你在轨道上!)我在控制台上有这个奇怪的消息。

Started GET "/" for 10.0.2.2 at 2017-02-25 23:42:38 +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 
    Parameters: {"internal"=>true} 
    Rendering /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.0.1/lib/rails/templates/rails/welcome/index.html.erb 
    Rendered /usr/local/lib/ruby/gems/2.4.0/gems/railties-5.0.1/lib/rails/templates/rails/welcome/index.html.erb (1.6ms) 
Completed 200 OK in 10ms (Views: 4.2ms | 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

谢谢!

回答

1

在任何计算机上运行的应用程序都可以在运行在同一台计算机上的其他应用程序上访问。在你的情况下,MacOS(主机)和Vagrant(客人)盒是两个不同的机器。因此,无法从主机访问绑定到Vagrant Box上的localhost界面的应用程序。

当你与rails s运行Rails应用,轨道将与接口localhost如下图所示

[email protected]:~$ netstat -an |grep LISTEN 
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN 
tcp  0  0 127.0.0.1:3000   0.0.0.0:*    LISTEN 

Rails应用程序是在流浪箱中运行其他应用程序访问。另一方面,如果您使用rails s -b 0.0.0.0运行rails应用程序,rails应用程序将绑定到所有接口,如下所示。

[email protected]:~$ netstat -an |grep LISTEN 
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN 
tcp  0  0 0.0.0.0:3000   0.0.0.0:*    LISTEN 

运行Rails应用程序与-b 0.0.0.0开辟了访问来自主机应用程序。

但是,在能够访问rails应用程序之前,还需要做更多的工作。看起来你已经有了你的Vagrantfile中的条目。但是,无论如何我都在这里添加它。

转发所需端口,如下所示在Vagrantfile中。

Vagrant.configure("2") do |config| 
    config.vm.network "forwarded_port", guest: 80, host: 8080 
    config.vm.network "forwarded_port", guest: 3000, host: 8000 
    config.vm.network "forwarded_port", guest: 3001, host: 8001 
    config.vm.network "forwarded_port", guest: 3002, host: 8002 
end 

可以使用http://localhost:8000访问运行在Vagrant端口3000上的rails应用程序。

人们可以通过加入这一行中config/environments/development.rb

config.web_console.whitelisted_ips = '10.0.2.2' 
禁用 Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255消息
相关问题