我在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?
答案 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步
第2步
现在按照您的流程运行rails server
命令。只需将命令修改为此rails server -b 0.0.0.0
并等待服务器启动。
获取您的盒子的IP地址(运行ifconfig),现在在Windows中打开任何浏览器,并将URL指定为ip_address_of_your_box:3000