端口使用Vagrant转发时连接重置

Mar*_*ark 29 django portforwarding connection-reset vagrant ubuntu-12.04

我有Vagrant/VirtualBox运行Ubuntu 12.04 LTS OS.我已将Vagrant配置为将来宾端口8000转发到我的主机端口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! 
Run Code Online (Sandbox Code Playgroud)

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

Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用Firefox/Chrome/Telnet从我的主机上攻击服务器时,我得到连接重置/连接丢失/ ERR_CONNECTION_RESET等.

首先我认为它可能是一些iptables的事情,但事实证明Ubuntu默认允许一切.我还关闭了主机上的防火墙.我怎样才能深究这一点?

Mar*_*ark 79

我让Django听了127.0.0.1:8000(默认)

正如Mitchell在这里的回答所解释的:Vagrant的端口转发不起作用我应该一直在听0.0.0.0.以下是他回答的引用:

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

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

  • 如果您正在使用 Rails,并且碰巧看到这篇 Django 帖子,那么您对应的 `rails` 选项是 `rails -b 0.0.0.0` (2认同)