python - 从 windows 浏览器访问 ubuntu 虚拟机主机

标签 python ubuntu flask virtualbox ubuntu-14.04

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












我们不允许在 Stack Overflow 上提出有关专业服务器或网络相关基础设施管理的问题。您可以编辑问题,使其成为 on-topic对于堆栈溢出。


7年前关闭。







Improve this question




我有一个运行 hell 世界 flask 应用程序的 virtualbox ubuntu 机器。

我尝试让应用程序显示在 127.0.0.1:5000 和 0.0.0.0:5000

但是当我尝试在我的 Windows 浏览器上加载时都无法解决。

当我在 ubuntu 虚拟机中运行 ifconfig 时,我得到了这个:

ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:6f:2c:93  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe6f:2c93/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:657 errors:0 dropped:0 overruns:0 frame:0
          TX packets:559 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:61322 (61.3 KB)  TX bytes:73104 (73.1 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

当我在我的 Windows 机器上运行 ip config 时,我得到了这个:
ipconfig

Windows IP Configuration


Ethernet adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2140:c809:4677:98bc%3
   IPv4 Address. . . . . . . . . . . : 10.32.16.32
   Subnet Mask . . . . . . . . . . . : 255.0.0.0
   Default Gateway . . . . . . . . . : 10.128.128.128

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::3568:3fc7:1697:a475%10
   IPv4 Address. . . . . . . . . . . : 192.168.56.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Tunnel adapter isatap.{2543650F-5CEA-40B8-B085-A54A628D3DCE}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter isatap.{8A555006-09A6-4A20-986D-F59F5741DCCE}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

但是由于某种原因,当我在 Windows 浏览器中转到 192.168.56.1 时,它会加载一个白页。如果我去 192.168.56.1:5000 它说它无法连接。

在我的虚拟盒子中,我将它“附加到:NAT”
和端口转发规则显示

ssh TCP 127.0.0.1 主机端口 2222 guest ip 为空, guest 端口为 22

我的 flask 应用程序显示
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat

也试过了
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat

最佳答案

回答您可以在 VirtualBox 文档中找到的问题:
https://www.virtualbox.org/manual/ch06.html
6.3.1.使用 NAT 配置端口转发

您可以将端口 5000 从 guest 操作系统 (Ubuntu) 转发到主机。在主机端,您可以使用相同的端口号(如果它没有被其他人占用,当然)

关于python - 从 windows 浏览器访问 ubuntu 虚拟机主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30118900/

相关文章:

python - 如何将列表元素转为字符串?

linux - Vagrant 配置脚本在 VM 完全启动之前运行?

python - 使用 paramiko 检查 SSH 是否可以完成

javascript - 单击清除文本框

python - Flask + Flask_SocketIO = 运行时错误 : Working outside of request context

Python Tornado 全局变量

python - 为什么 render_to_response 无法正常工作

python - 显示图像时尺寸无效

python - 加载 csv 文件时出现内存错误?

postgresql - 如何使用 SQLAlchemy 执行 SELECT DISTINCT ON 查询