2015-09-13 46 views
-1

我已经安装了所有必要的工具来启动和运行vagrant。我可以通过putty从Windows主机登录vm guest。但是,当我尝试使用我的端口转发指定的端口从主机Windows操作系统访问本地主机,我不能够访问端口转发不在Vagrant工作

enter image description here

+0

当我试图访问它使加载页面,并显示服务器未找到!我使用:http:// localhost:8080/index.html –

+0

你有什么东西在虚拟机端口80上运行?尝试与http://127.0.0.1:8080/index.html –

+0

对不起,我没有安装任何其他程序使用端口80.我也尝试127.0.0.1.:8080/index.html,但仍然不工作 –

回答

0

我将它作为一个答案,因为它会更加明朗比在评论写作:

  • 从你展示它是什么并不清楚你已经安装了Apache,Nginx的或其他web服务器,所以没有你得到预期的行为。

  • 从VM,去运行sudo netstat -ant(你需要须藤否则就不能检测以root权限运行的进程的PID),你应该有一些看起来像

    [email protected]:/etc/init.d$ sudo netstat -nltp 
    Active Internet connections (only servers) 
    Proto Recv-Q Send-Q Local Address   Foreign Address   State  PID/Program name 
    tcp  0  0 0.0.0.0:111    0.0.0.0:*    LISTEN  512/rpcbind 
    tcp  0  0 0.0.0.0:80    0.0.0.0:*    LISTEN  1827/apache2 
    tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN  652/sshd 
    tcp  0  0 0.0.0.0:58397   0.0.0.0:*    LISTEN  539/rpc.statd 
    tcp6  0  0 :::111     :::*     LISTEN  512/rpcbind 
    tcp6  0  0 :::22     :::*     LISTEN  652/sshd 
    tcp6  0  0 :::54908    :::*     LISTEN  539/rpc.statd 
    

最重要的部分是0 0.0.0.0:80所以我必须在80端口运行的进程,并在我的情况下,其apache2

如果你没有看到的东西在端口80上运行,你需要安装,运行sudo apt-get install apache2它将安装/启动的Apache2服务,你就可以去

  • 现在检查是否有东西在页面上返回从虚拟机,你可以运行curl或任何你喜欢的

    [email protected]:/etc/init.d$ curl localhost 
    <html><body><h1>It works!</h1> 
    <p>This is the default web page for this server.</p> 
    <p>The web server software is running but no content has been added, yet.</p> 
    </body></html> 
    

所以在这里它的细腻,我的页面显示。

现在,当我去到主机,做同样的,我可以看到在同一页

[email protected]:~/project/examples/vagrant/ssh$ curl http://localhost:8080 
<html><body><h1>It works!</h1> 
<p>This is the default web page for this server.</p> 
<p>The web server software is running but no content has been added, yet.</p> 
</body></html> 
[email protected]:~/project/examples/vagrant/ssh$ curl http://127.0.0.1:8080 
<html><body><h1>It works!</h1> 
<p>This is the default web page for this server.</p> 
<p>The web server software is running but no content has been added, yet.</p> 
</body></html> 
[email protected]:~/project/examples/vagrant/ssh$ 
+0

我使用的是Ubuntu/trusty64,我认为它已经预装了apache。现在我已经运行了命令netstat -nltp,但是我看不到0.0.0.0:80。请让我知道如何在我的虚拟机上安装apache, –

+0

编辑答案,基本上''sudo apt-get install apache2' –

+0

@AmitKumar,请记得接受/投票答案,如果它帮助你 –