[英]How to access service running in WSL2 from Windows host using 127.0.0.1?
我在 WSL2 端口 8080 上啟動並運行了一個 Express API 服務器。我試圖從運行 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
wsl --shutdown
中的wsl --shutdown
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.