我已经在Ubuntu 14.04 VM上安装了Rails 4.2作为开发环境。当我用rails s
启动rails服务器时,服务器说它启动并正在监听http://localhost:3000
上的连接
如果我尝试访问<IP>:3000
,则不会显示任何页面,也不会触及rails服务器的日志。如果我从机器中执行curl localhost:3000
,我会得到我主页的html。
如果我执行rails s -b 0.0.0.0
,我可以通过其IP地址访问服务器。
在我的MacBook Pro上,运行rails s
(收听localhost
)可让我通过localhost:3000
或<IP>:3000
访问rails应用。
答案 0 :(得分:11)
http://edgeguides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server
Rails 4.2发行说明说,现在rails服务器的默认主机是localhost。
因此,如果您想从其他计算机访问应用程序,请使用
rails server -b 0.0.0.0
可能你的Macbook Pro使用旧的Rails版本,旧行为