从Windows上访问在Vagrant框上运行的rails服务器

Glu*_*ear 3 windows ruby-on-rails vagrant

我在Windows机器上,运行Vagrant盒子ubuntu/xenial64,上面安装了Rails.当我进入框中并创建一个rails应用程序,cd进入文件夹并运行时rails server,它会告诉我

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

听取tcp://0.0.0.0:3000

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

Fré*_*nri 6

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

config.vm.network "forwarded_port", guest: 3000, host: 3000
Run Code Online (Sandbox Code Playgroud)

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

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