在vmwate的CentOS7的虚拟机中安装在rails 4.2.0 版本以后,无法通过其他机器访问 3000端口的问题

来源:互联网 发布:彗星dns优化器官方 编辑:程序博客网 时间:2024/06/09 15:19

在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] INFO  WEBrick 1.3.1[2016-01-20 01:14:37] INFO  ruby 2.2.1 (2015-02-26) [x86_64-linux][2016-01-20 01:14:37] INFO  WEBrick::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 to localhost by default, instead of 0.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.0 to make the rails server accessible from the host computer/browser.

http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-serverhttps://github.com/samuelkadolph/unicorn-rails/issues/12#issuecomment-60875268


解决办法 :


使用 如下命令


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] INFO  WEBrick 1.3.1[2016-01-20 01:21:05] INFO  ruby 2.2.1 (2015-02-26) [x86_64-linux][2016-01-20 01:21:05] INFO  WEBrick::HTTPServer#start: pid=2580 port=3000


0 0
原创粉丝点击