1

问题

尽管使用了可接受的专用网络和转发端口,但我无法连接到我的虚拟机环境。

描述

系统

vagrant up之后,我进入vagrant ssh了我的虚拟盒子。以下请求按预期工作:

[06:04 PM]-[vagrant@precise64]-[~]
$ curl -v 192.168.56.101
* About to connect() to 192.168.56.101 port 80 (#0)
*   Trying 192.168.56.101... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: 192.168.56.101
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 09 Jul 2014 18:05:05 GMT
< Server: Apache/2.4.9 (Ubuntu)
< Vary: Accept-Encoding
< Content-Length: 481
< Connection: close
< Content-Type: text/html;charset=UTF-8
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /</title>
 </head>
 <body>
<h1>Index of /</h1>
  <table>
   <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
   <tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
* Closing connection #0

[06:05 PM]-[vagrant@precise64]-[~]
$ curl -v playworldsystems.dev
* About to connect() to playworldsystems.dev port 80 (#0)
*   Trying 192.168.56.101... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: playworldsystems.dev
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 09 Jul 2014 18:05:52 GMT
< Server: Apache/2.4.9 (Ubuntu)
< X-Powered-By: PHP/5.5.14-2+deb.sury.org~precise+1
< Vary: Accept-Encoding
< Content-Length: 122
< Connection: close
< Content-Type: text/html
<
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'hello'</font> <i>(length=5)</i>
* Closing connection #0
</pre>

但是,当我在 HOST 终端中尝试这两个命令时,我收到以下错误:

curl -v 192.168.56.101
* About to connect() to 192.168.56.101 port 80 (#0)
*   Trying 192.168.56.101...
* Adding handle: conn: 0x7fc6f1000000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fc6f1000000) send_pipe: 1, recv_pipe: 0
* Failed connect to 192.168.56.101:80; Operation timed out
* Closing connection 0
curl: (7) Failed connect to 192.168.56.101:80; Operation timed out
☁  ~  curl -v playworldsystems.dev
* Adding handle: conn: 0x7fdbe9803000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fdbe9803000) send_pipe: 1, recv_pipe: 0
* About to connect() to playworldsystems.dev port 80 (#0)
*   Trying 192.168.56.101...
* Failed connect to playworldsystems.dev:80; Operation timed out
* Closing connection 0
curl: (7) Failed connect to playworldsystems.dev:80; Operation timed out

即使在尝试从端口6969和卷曲之后8080,我仍然没有成功。我使用了随机 IP 地址和端口。我尝试将我的虚拟主机更改为其他端口号。似乎没有任何效果。我会提到,当第一次开始时,我注意到这个 vagrant 设置已经奏效了——只有两次。每次它工作时,我都会vagrant suspendvagrant up第二天早上发现我之前的解决方案不再有效。

也许这个事实使这个过程如此令人沮丧。我想为我当前的项目获取 MAMP,但担心是我的工作机器的设置受到干扰,或者可能是其他一些与应用程序或网络相关的问题。我不确定要采取什么步骤,并期待任何和所有解决方案。

4

1 回答 1

4

一些提示/指针。

  1. 检查防火墙规则是否没有阻止端口,如果一切都失败,只需禁用它以测试“iptables -F”
  2. 确保端口正确转发https://docs.vagrantup.com/v2/networking/forwarded_ports.html 所以你想要的 http 是 host:8080 guest:80
  3. 有时您的主机上的 IP 地址会发生变化(例如,获取新的 dhcp 或加入新的网络 home/work/vpn )
    检查您是否可以通过正确适配器的正确 IP 从主机 ping 您的 VM 来宾。在主机上运行“ifconfig -a”(在 mac 上应该有一些以太网的 en0 和机场的 en1)如果你可以 ping vm 来宾,那么你可以通过端口 8080 访问 Web 服务器( http://mylocal. dev:8080/)当然前提是您编辑了 /etc/hosts 以将您的虚拟主机指向上述 IP 地址。
于 2014-07-10T20:38:55.477 回答