在vmwate的CentOS7的虚拟机中安装在rails 4.2.0 版本以后,无法通

2016-12-03 14:06:50来源:网络收集作者:Worker人点击

在vmware 的虚拟机中安装了 CentOS7 ,并且安装了 ruby 2.2.1 和 rails 4.2.4


通过 rails s 启动WEBrick ,出现以下问题:3000端口除了本机,其他机器无法访问(防火墙已经关闭)


=> Booting WEBrick
=> Rails 4.2.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-01-20 01:14:37] INFOWEBrick 1.3.1
[2016-01-20 01:14:37] INFOruby 2.2.1 (2015-02-26) [x86_64-linux]
[2016-01-20 01:14:37] INFOWEBrick::HTTPServer#start: pid=2482 port=3000


rails 只绑定了 localhost 的 3000 端口。这样就导致只能本地访问3000端口。其他机器无法访问,用telnet 192.168.1.158 3000 这种方式去查看端口状态,直接给拒绝。


出现这种问题的原因是 :


down vote


with rails 4.2.0, the server binds tolocalhostby
default, instead of0.0.0.0.
When working with a rails in a virtual box, accessing the server from the host computer, the binding address needs to be 0.0.0.0



Start rails server with-b0.0.0.0to
make the rails server accessible from the host computer/browser.



/2014th7cj/d/file/p/20161203/fejtl0whqnm.html :


使用 如下命令


rails s -b0.0.0.0
查看控制台信息,确定用0.0.0.0 来代替 localhost


[roamer@ror_server demo]$ rails s -b0.0.0.0
=> Booting WEBrick
=> Rails 4.2.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-01-20 01:21:05] INFOWEBrick 1.3.1
[2016-01-20 01:21:05] INFOruby 2.2.1 (2015-02-26) [x86_64-linux]
[2016-01-20 01:21:05] INFOWEBrick::HTTPServer#start: pid=2580 port=3000

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台