Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用127.0.0.1从Windows主机访问WSL2中运行的服务?_Windows_Api_Localhost_Windows Subsystem For Linux_Wsl 2 - Fatal编程技术网

如何使用127.0.0.1从Windows主机访问WSL2中运行的服务?

如何使用127.0.0.1从Windows主机访问WSL2中运行的服务?,windows,api,localhost,windows-subsystem-for-linux,wsl-2,Windows,Api,Localhost,Windows Subsystem For Linux,Wsl 2,我有一个Express API服务器,在端口8080的WSL2上运行。我试图从运行Postman和浏览器的Windows主机上使用127.0.0.1访问端点,但无法访问API。将127.0.0.1更改为localhost有效,但我想知道为什么127.0.0.1无效。可能Windows的主机文件与此路由/转发冲突 以下是Windows主机文件: # 127.0.0.1 localhost ::1 localhost # Added by Docker Desktop 192.168.0.14 ho

我有一个Express API服务器,在端口8080的WSL2上运行。我试图从运行Postman和浏览器的Windows主机上使用
127.0.0.1
访问端点,但无法访问API。将
127.0.0.1
更改为
localhost
有效,但我想知道为什么
127.0.0.1
无效。可能Windows的主机文件与此路由/转发冲突

以下是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
# 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
以下是WSL2主机文件:

#
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
# 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
#此文件由WSL自动生成。要停止自动生成此文件,请将以下条目添加到/etc/wsl.conf:
#[网络]
#generateHosts=false
127.0.0.1本地主机
127.0.1.1主机。本地域主机
127.0.0.1本地主机
::1本地主机
192.168.0.14 host.docker.internal
192.168.0.14 gateway.docker.internal
127.0.0.1 kubernetes.docker.internal
#以下线路适用于支持IPv6的主机
::1 ip6本地主机ip6环回
fe00::0 ip6 localnet
ff00::0 ip6 mcastprefix
ff02::1 ip6所有节点
ff02::2 ip6所有路由器

我只想在Windows中点击
127.0.0.1
,然后在WSL2中运行我的API来响应。这可能吗?谢谢你的帮助

我需要这些东西来处理WSL2

  • wsl--在powershell中关闭
  • 设置>网络和Internet>网络重置为
  • 将Windows“高级”防火墙配置为向所有网络打开端口(WSL是公共的)