neu*_*ert 9 hyper-v ubuntu windows-10 wsl2 ubuntu-20.04
我在 WSL2/Hyper-V/Windows 10 上运行 Ubuntu 20.04。
当我curl http://127.0.0.1在 Ubuntu 里面做的时候,我得到了这个:
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.19.3</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我在主机上执行此操作时 - 在 Windows 10 本身(使用 Git Bash)上,我得到以下信息:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
Run Code Online (Sandbox Code Playgroud)
如何在 Ubuntu 之外访问端口 80?我是否需要更新 Windows 中的防火墙规则?
小智 12
这对我有用,就像 localhost/127.0.0.1 我没有运气:
Run Code Online (Sandbox Code Playgroud)aristos32@DESKTOP-V493N00:~$ ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.21.115.144 netmask 255.255.240.0 broadcast 172.21.127.255 inet6 fe80::215:5dff:fea0:1a98 prefixlen 64 scopeid 0x20<link>
http://172.21.115.144/
Mar*_*eck 10
这是因为每个主机都有一个 localhost 127.0.0.1。Windows 主机认为它会自行处理。最简单的解决方案是您使用真实 IP 进行 IP 分配。示例 192.168.xx
\n我发现了以下简介
\n在 WSL 2 的早期阶段,我们可以\xe2\x80\x99t 使用 localhost。我们需要使用 IP,因为 Linux 位于虚拟机内。
\n目前,为了访问您的应用程序,我们将使用 IP。
\nMic*_*ole 10
Windows 10 认为 localhost 是::1.
PS C:\Users\michael> ping localhost
Pinging DESKTOP[::1] with 32 bytes of data:
Reply from ::1: time<1ms
Run Code Online (Sandbox Code Playgroud)
Ubuntu 认为 localhost 是 127.0.0.1
$ ~ > cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 DESKTOP.localdomain DESKTOP
Run Code Online (Sandbox Code Playgroud)
WSL 的变化相对较快。
我目前使用 WSL2 的解决方案是
C:\Users\Me\.wslconfig:[wsl2]
localhostForwarding=true
Run Code Online (Sandbox Code Playgroud)
这对我有用。
这对我来说不是很好,但可能对你有用。按照 中的注释中的说明停止自动生成/etc/hosts,并将 localhost 更改为,::1以便它们引用相同的适配器。为了兼容性,0.0.0.0绑定到所有接口(127.0.0.1 和 ::1)所以它可以工作。
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 ip4-localhost
::1 localhost
...
Run Code Online (Sandbox Code Playgroud)
这会搞砸吗?大概。如果是这样,您将不得不记住摆弄它以使其工作。
| 归档时间: |
|
| 查看次数: |
13610 次 |
| 最近记录: |