小编Aab*_*nja的帖子

localhost 和 127.0.0.1 工作但在 wsl windows 10 中不工作

我最近在 Windows 10 上从 Linux 切换到 WSL2 (Ubuntu 20.04)。当我运行任何 NodeJs 应用程序或 Apache 或 Nginx 等服务器时,一切都在 localhost 或 127.0.0.1 上正常工作,但当我使用本地 IP 地址时则无法工作( 192.168.1.65)。

运行 Node js 应用程序时的 netstat -tupln

我尝试过关闭 Windows 和 wsl 中的防火墙,但没有用。

我从“程序和功能”启用了 IIS,它似乎在 localhost 和 ip 上运行良好。所以,我认为这不是网络问题。

用于测试目的的 IIS

我读过的所有帖子都表明,如果可以通过 127.0.0.1 而不是通过 ip 访问该站点,那么您可以为 Apache 或 Nginx 配置服务器配置文件。但我重新安装了 wsl 并且仅通过 NodeJs / Express 进行托管。

Express 应用程序的 server.js 的代码是:

const express = require("express");
const next = require("next");

const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== …
Run Code Online (Sandbox Code Playgroud)

linux ip localhost node.js windows-subsystem-for-linux

6
推荐指数
1
解决办法
2万
查看次数