如何解决如何使用127.0.0.1从Windows主机访问WSL2中运行的服务?
我有一个Express API服务器并在端口8080上的WSL2上运行。我试图从运行Postman和浏览器的主机Windows计算机上使用127.0.0.1
访问端点,但是无法访问API 。将127.0.0.1
更改为localhost
可行,但我想知道为什么127.0.0.1
不可行。也许Window的主机文件与此路由/转发冲突?
这是Windows主机文件:
#
127.0.0.1 localhost
::1 localhost
# Added by Docker Desktop
192.168.0.14 host.docker.internal
192.168.0.14 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
这是WSL2主机文件:
# 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 HOST.localdomain HOST
<feff>
127.0.0.1 localhost
::1 localhost
192.168.0.14 host.docker.internal
192.168.0.14 gateway.docker.internal
127.0.0.1 kubernetes.docker.internal
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
我要做的只是从Windows中击127.0.0.1
,然后在WSL2中运行我的API进行响应。这可能吗?谢谢您的帮助!
解决方法
我需要这些东西才能与WSL2一起使用
- Upgrade to the latest version of windows
-
wsl --shutdown
in powershell - 设置>网络和Internet>网络重置为described here
- 配置Windows“高级”防火墙以打开所有网络的端口(WSL是公共的)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。