来自服务器的空回复 - 无法连接到带有端口转发的 vagrant vm [英] Empty reply from server - can't connect to vagrant vm w/port forwarding

查看:30
本文介绍了来自服务器的空回复 - 无法连接到带有端口转发的 vagrant vm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Vagrant VM 中运行 werkzeug(作为 Tilestache 设置的一部分),运行 ubuntu '精确'.

I'm running werkzeug (as part of a Tilestache setup) inside a Vagrant VM, running ubuntu 'precise.'

在我的 Vagrantfile 中,我有:

In my Vagrantfile, I have:

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

当我在 VM 中启动服务器时,我看到:

When I start the server in the VM, I see:

 * Running on http://127.0.0.1:8080/

如果我在虚拟机中curl那个地址,我会得到预期的结果.当我从主机curl它时,我得到:

If I curl that address from within the VM, I get the expected result. When I curl it from the host machine, I get:

curl: (52) Empty reply from server

Chrome 显示未收到任何数据."

And Chrome says "No data received."

问题排查信息:

  • 服务器响应来自主机的 ping
  • 端口嗅探器验证端口是否打开
  • 运行 netstat -ntlp |vm中的grep 8080显示服务器正在监听8080
  • 我的本地主机文件没有任何奇怪的冲突
  • 我也转发了 22 => 2222,我可以毫无问题地进行 ssh 连接
  • 我已禁用主机上的防火墙,但我认为来宾上没有防火墙(至少 iptables 和 ufw 已禁用)
  • 我已经设置了 auto_correct: true 以防有冲突(没有)
  • The server responds to pings from the host machine
  • a port sniffer verifies that the port is open
  • running netstat -ntlp | grep 8080 in the vm shows that the server is listening on 8080
  • My local hostsfile doesn't have any weird conflicts
  • I'm also forwarding 22 => 2222, and I can ssh in with no trouble
  • I've disabled the firewall on the host, and i don't believe there's one on the guest (iptables and ufw are disabled, at least)
  • I've set auto_correct: true in case there are conflicts (there aren't)

我知道我可以设置专用网络,但我想了解为什么这不起作用以及如何进行故障排除.

I know I could set up a private network, but I'd like to understand why this isn't working and how to troubleshoot it.

还有其他想法吗?

推荐答案

当从 VM 内运行服务器时,在 0.0.0.0 而不是 127.0.0.1 上启动服务器强>.

When running a server from within a VM, start the server on 0.0.0.0 instead of 127.0.0.1.

127.0.0.1 只能被本地机器访问,这对于虚拟机来说意味着虚拟机之外的任何东西都无法访问它!0.0.0.0 可以从本地网络上的任何地方访问,对于虚拟机来说,包括主机.

127.0.0.1 is only accessible to the local machine, which for a VM means nothing outside of the VM can reach it! 0.0.0.0 is accessible from anywhere on the local network, which to a VM includes the host machine.

答案来自这里:使用 Vagrant 进行端口转发时的连接重置

(显然从这里得到了答案:https://stackoverflow.com/a/5999945/738675)

(Which apparently got its answer from here: https://stackoverflow.com/a/5999945/738675)

在以下方面的帮助下:https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1

如果这是问题,您可能会收到以下错误:

Here are the errors you might receive if this is the problem:

  • Chrome:未收到数据"
  • Firefox:连接已重置 - 加载页面时与服务器的连接已重置."
  • Safari:Safari 无法打开页面 [URL],因为服务器意外断开连接"
  • curl:来自服务器的空回复"

这篇关于来自服务器的空回复 - 无法连接到带有端口转发的 vagrant vm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆