gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:47:10 32 4
gpt4 key购买 nike

关闭。这个问题不符合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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com