Vagrant 上的 Rails 4.2 服务器端口转发不起作用 [英] Rails 4.2 Server port forwarding on Vagrant does not work

查看:46
本文介绍了Vagrant 上的 Rails 4.2 服务器端口转发不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装了 Rails 的 Vagrant VM 和一个示例应用程序.VM 配置为将端口 3000(Rails Webrick 服务器的)转发到我的主机 3000 端口.

I have a Vagrant VM with Rails installed with a sample app. The VM is configured to forward the port 3000 (of Rails Webrick server) to my host 3000 port.

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

一切都按照许多示例中的说明进行配置.

Everything is configured as seen in a lot of examples.

但是,当我尝试访问 http://localhost:3000 时没有任何反应.我还尝试转发到其他随机端口,如 8081、25600,但没有成功.执行 curl 请求也不会得到任何东西(只是对等方重置连接 消息),并且 VM 内的 curl 请求工作正常(如预期).

But, when I try to access http://localhost:3000 nothing happens. I've also tried to forward to other random ports like 8081, 25600, without success. Doing a curl request also does not get anything (just a Connection reset by the peer message), and a curl request inside VM works perfectly (as expected).

我的 PC 和 VM 都运行 Ubuntu 12.04.我使用的是 Ruby 2.2.0 和 Rails 4.2.0.

Both my PC and my VM runs Ubuntu 12.04. I'm using Ruby 2.2.0 and Rails 4.2.0.

重要的一点是Apache正常工作.我将端口 80 转发到端口 8080,一切正常.似乎问题仅出在 Rails 服务器上,即使我使用其他端口(例如,rails server -p 4000)

An important point is that Apache works normally. I forwarded the port 80 to port 8080 and everything works. It seems that the problem is just with the Rails server, even if when I use other ports (rails server -p 4000, for example)

推荐答案

Rails 4.2 现在默认绑定到 127.0.0.1 而不是 0.0.0.0.

Rails 4.2 now binds to 127.0.0.1 by default and not 0.0.0.0.

使用 bin/rails server -b 0.0.0.0 启动服务器,然后对它进行排序.

Start the server using bin/rails server -b 0.0.0.0 and that should sort it.

这篇关于Vagrant 上的 Rails 4.2 服务器端口转发不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆