“wsl:检测到 localhost 代理配置,但未镜像到 WSL......”解决办法

wsl

之前一直是使用的mac作为工作电脑,最近切换到Windows电脑,使用wsl时每次都会提示wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理

询问ChatGPT,得到的答案是:在 WSL (Windows Subsystem for Linux) 中,出现 "检测到 localhost 代理配置,但未镜像到 WSL" 的提示,通常是因为 WSL 2 使用 NAT 网络隔离了 WSL 和 Windows 主机的网络环境。导致 localhost 或 127.0.0.1 的代理配置指向的是 WSL 的本地网络,而不是 Windows 主机的网络

WSL issues #10753找到解决办法,记录如下:

  1. 打开或创建wsl.conf文件,路径为:%USERPROFILE%\.wslconfig,增加以下内容:

    [experimental]
    autoMemoryReclaim=gradual  # gradual  | dropcache | disabled
    networkingMode=mirrored
    dnsTunneling=true
    firewall=true
    autoProxy=true
    
  2. 关机重启wsl后即可。


孟斯特
> 声明:本作品采用[署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh)进行许可,使用时请注明出处。 > Author: [mengbin](mengbin1992@outlook.com) > blog: [mengbin](https://mengbin.top) > Github: [mengbin92](https://mengbin92.github.io/) > cnblogs: [恋水无意](https://www.cnblogs.com/lianshuiwuyi/) > 腾讯云开发者社区:[孟斯特](https://cloud.tencent.com/developer/user/6649301) ---