从Windows

时间:2017-07-20 09:55:25

标签: ruby-on-rails windows vagrant

我在Windows计算机上,并且有一个运行ubuntu/xenial64的Vagrant框,其上安装了Rails。当我进入框中并创建一个rails应用程序cd进入该文件夹并运行rails server时,它会告诉我

  

Rails 5.1.2应用程序从http://localhost:3000

开发开始      

收听tcp://0.0.0.0:3000

我现在想在我的Windows机器上访问localhost:3000,但它说未找到。如何使rails服务器可用于Windows?

2 个答案:

答案 0 :(得分:5)

您需要确保已将端口3000从VM转发到主机,在Vagrantfile中添加此行

config.vm.network "forwarded_port", guest: 3000, host: 3000

这样您就可以从Windows计算机上的localhost:3000访问rails应用程序

正如其他人所说,最好使用rails server -b 0.0.0.0启动rails服务器,以便它绑定到所有网络接口

答案 1 :(得分:3)

我正在使用VirtualBox(运行Ubuntu 14)作为我的rails应用程序。我已经完成了以下更改以访问我的Windows机器上的localhost

第1步

  • 转到设置 - >网络并将 NAT适配器更改为桥接适配器。也在网络 - >提前检查允许所有用于混杂模式。
  • 重新启动VM / Box

第2步

  • 现在按照您的流程运行rails server命令。只需将命令修改为此rails server -b 0.0.0.0并等待服务器启动。

  • 获取您的盒子的IP地址(运行ifconfig),现在在Windows中打开任何浏览器,并将URL指定为ip_address_of_your_box:3000

    例如:http://10.0.0.191:3000