【问题标题】:Vagrant and Rails server: cannot connect to localhostVagrant 和 Rails 服务器:无法连接到 localhost
【发布时间】:2017-06-12 12:48:36
【问题描述】:

我正在尝试从 Vagrant 上的 Ubuntu 12.04 64 位虚拟机运行 Rails 应用程序。运行rails serverrails server -b 0.0.0.0 都可以,但在这两种情况下,当我尝试从本地Windows 10 机器访问localhost:30000.0.0.0:3000 时,它都会显示ERR_CONNECTION_REFUSED

我也把这一行放在 Vagrantfile 中:

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

理论上应该允许在 3000 上进行端口转发,但是当我运行 netstat -ntlp 时,我得到:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:50891           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp6       0      0 :::111                  :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::36063                :::*                    LISTEN      -

所以不知何故,我的 Vagrant 机器并没有监听 3000 端口。

我也试过vagrant reload,但无济于事。 Rails 版本是 5.0.1。

我在哪里失败了?提前致谢。

【问题讨论】:

    标签: ruby-on-rails vagrant localhost


    【解决方案1】:

    解决了。 Vagrantfile 中的行必须是:

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

    所以用冒号代替引号。

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 2020-07-14
      • 2017-11-10
      相关资源
      最近更新 更多