使用Vagrant进行端口转发时连接重置 [英] Connection Reset when port forwarding with Vagrant

查看:913
本文介绍了使用Vagrant进行端口转发时连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Vagrant / VirtualBox运行Ubuntu 12.04 LTS操作系统。我已配置Vagrant将客户端口8000转发到我的主机端口8888。

  [default]根据配置准备网络接口。 .. 
[默认]转发端口...
[default] - 22 => 2222(适配器1)
[default] - 8000 => 8888(适配器1)
[默认值]引导VM ...
[默认值]等待虚拟机启动。这可能需要几分钟的时间。
[默认] VM启动并准备使用!

当虚拟机启动时,我在端口8000上启动一个Django dev服务器。

 开发服务器正在运行http://127.0.0.1:8000/ 
使用CONTROL-C退出服务器。

好的,我可以把它放在后台,我甚至可以卷曲localhost:8000 并从服务器获取一些输出

 < div id =explain> ; 
< p>
您看到此消息,因为您有< code> DEBUG = True< / code>在
Django设置文件中,您尚未配置任何URL。上班!
< / p>
< / div>

但是当我尝试使用Firefox / Chrome / Telnet从主机上点击服务器时, m连接重置/连接丢失/ ERR_CONNECTION_RESET等。



首先我以为可能是一些iptables的东西,但事实证明,Ubuntu的默认允许一切。我也关闭了我的主机上的防火墙。我如何得到这个的底部?

解决方案

我有Django听127.0.0.1:8000(默认) p>

如Mitchell的回答中所述: Vagrant的端口转发不工作我应该听0.0.0.0。这是他的答案的引用:


我想添加一个额外的注释,这通常是由
服务器引起的因为VM绑定到127.0.0.1,这是环回。
您需要确保服务器绑定到0.0.0.0,以便
所有接口可以访问它。


如果你使用Django,你想像这样启动开发者服务器: ./ manage.py runserver 0.0.0.0:8000


I have Vagrant/VirtualBox running an Ubuntu 12.04 LTS OS. I have configured Vagrant to forward the guest port 8000 to my host port 8888.

[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] -- 8000 => 8888 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use! 

When the virtual machine starts up, I start a Django dev server on port 8000.

Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Okay great, I can put it in the background and I can even curl localhost:8000 and get some output from the server

<div id="explanation">
  <p>
    You're seeing this message because you have <code>DEBUG = True</code> in your
    Django settings file and you haven't configured any URLs. Get to work!
  </p>
</div>

But when I try to hit the server from my host machine with a Firefox/Chrome/Telnet I'm getting Connection Reset/Connection Lost/ERR_CONNECTION_RESET etc.

First I thought it may be some iptables thing, but it turns out Ubuntu has default allow everything. I also turned off the firewall on my host machine. How can I get to the bottom of this?

解决方案

I had Django listening on 127.0.0.1:8000 (default)

As explained in Mitchell's answer here: Vagrant's port forwarding not working I should have been listening on 0.0.0.0. Here is a quote of his answer:

I wanted to add an additional note that often this is caused by the server within the VM because it binds to 127.0.0.1, which is loopback. You'll want to make sure that the server is bound to 0.0.0.0 so that all interfaces can access it.

If you're using Django, you want to start the dev server like this: ./manage.py runserver 0.0.0.0:8000

这篇关于使用Vagrant进行端口转发时连接重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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