【问题标题】:Unable to connect to mean.io in Vagrant无法连接到 Vagrant 中的 mean.io
【发布时间】:2015-04-27 20:35:18
【问题描述】:

在设置运行 CentOS7 的 vagrant 后,我​​无法连接到 mean.io 服务器。我有端口转发并禁用/打开防火墙,但在 wget 或 curl -v 上仍然没有响应。

我已自动执行以下步骤以达到我现在的位置:

git clone git@github.com:Scrier/Vagrant.git
cd Vagrant/mean
vagrant up

在这里我得到了端口转发设置的输出:

==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Couldn't find Cheffile at ./Cheffile.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 3000 => 3000 (adapter 1)
    default: 35729 => 35729 (adapter 1)
    default: 80 => 8888 (adapter 1)
    default: 22 => 2222 (adapter 1)
...

下一步是在 Vagrant 内部:

vagrant ssh
cd /vagrant
sudo ./install.sh
sudo npm install -g gulp
sudo npm install -g bower
sudo npm install -g mean-cli

最后 3 个命令有时不起作用,在后面的步骤中抱怨某些 npm:s 归 root 所有。不知道是什么触发了这个。

接下来我在 /vagrant 中创建一个测试项目

mean init test

然后我尝试作为 gulp (cd test && npm install && gulp) 或服务器 (node server) 运行

默认应用程序启动良好并开始侦听端口 3000。我可以在 vagrant 上 curl 并在服务器应答的情况下在 localhost 上执行 wget。

curl 'http://localhost:3000'
wget 'http://localhost:3000'

从 vagrant 外部执行此操作会锁定,经过 3 天的搜索,我现在无法在网上找到更多帮助。

curl -v 'http://localhost:3000'
wget 'http://localhost:3000'

给出这个输出:

Andreass-MBP:~ andreasjoelsson$ wget 'http://localhost:3000'
--2015-04-21 20:50:30--  http://localhost:3000/
Resolving localhost... 127.0.0.1, ::1, fe80::1
Connecting to localhost|127.0.0.1|:3000... connected.
HTTP request sent, awaiting response... ^C

Andreass-MBP:~ andreasjoelsson$ curl -v 'http://localhost:3000'
* Rebuilt URL to: http://localhost:3000/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:3000
> Accept: */*
>
^C

都停止响应。

我已经阅读了关于设置 ip 0.0.0.0 而不是 localhost 来解决运行 nodejs 的类似问题,但是我找不到任何有意义的配置。

【问题讨论】:

    标签: vagrant centos7 mean.io


    【解决方案1】:

    因此,经过很长一段时间的努力,我通过在此线程中尝试一个建议来实现它:Empty reply from server - can't connect to vagrant vm w/port forwarding

    通过将 localhost 的 /etc/hosts 中的 127.0.0.1 更改为 0.0.0.0,它开始工作。似乎很奇怪,我不得不去攻击 /etc/hosts 而不是 mean.io 中的设置,但我让它工作了,所以我会悄悄地忘记它并且很高兴它工作。

    以下是使其工作的快速命令。

    sed -i -E "s/127.0.0.1(.*)/0.0.0.0\1 # Replaced 127.0.0.1 to work with Vagrant external access./" /etc/hosts
    

    可能需要以 root 身份运行它。

    【讨论】:

      猜你喜欢
      • 2015-02-22
      • 1970-01-01
      • 2015-10-11
      • 2021-06-20
      • 1970-01-01
      • 2016-11-12
      • 2015-07-05
      • 2019-07-09
      • 2017-03-16
      相关资源
      最近更新 更多