[英]How to access service running in WSL2 from Windows host using 127.0.0.1?
I have an Express API server up and running on WSL2 on port 8080. I am trying to access the endpoints using 127.0.0.1
from my host Windows machine where I run Postman and my browsers, but I cannot access the API.我在 WSL2 端口 8080 上启动并运行了一个 Express API 服务器。我试图从运行 Postman 和浏览器的主机 Windows 机器上使用
127.0.0.1
访问端点,但我无法访问 API。 Changing 127.0.0.1
to localhost
works but I was wondering why doesn't 127.0.0.1
work.将
127.0.0.1
更改为localhost
有效,但我想知道为什么127.0.0.1
不起作用。 Perhaps Window's host files are conflicting with this route/forward?也许 Window 的主机文件与此路由/转发冲突?
Here is the Windows host file:这是 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
Here is the WSL2 host file:这是 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
All I want is to hit 127.0.0.1
from Windows and my API running in WSL2 to respond.我想要的只是从 Windows 命中
127.0.0.1
并且我在 WSL2 中运行的 API 进行响应。 Is this possible?这可能吗? Thank you for the help!
感谢您的帮助!
I needed these things to this to work with WSL2我需要这些东西才能使用 WSL2
wsl --shutdown
in powershell wsl --shutdown
中的wsl --shutdown
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.