【发布时间】:2022-01-05 08:33:20
【问题描述】:
我创建了一个基本的快递应用
const express = require('express');
const app = express();
app.get("*", (req, res) => {;
res.contentType('html');
res.send("HELLO FROM WSL");
});
const port = 80
app.listen(port);
然后我在c:\windows\system32\drivers\etc\hosts中添加以下条目
127.0.0.1 custom.local
然后我关闭 wsl wsl --shutdown 并重新打开以启动我的 express 应用程序。
如果我从 WSL (cat /etc/hosts) 检查主机文件,我会得到以下结果
# 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 LAPTOP-ZECKA.localdomain LAPTOP-ZECKA
127.0.0.1 custom.local
然后我去http://custom.local windows 中的槽 chome。但它不显示我的快递应用程序。 (如果我在 windows 而不是 wsl 上运行 express 则效果很好)。
我的主机文件有什么问题?
【问题讨论】:
-
我确实有同样的问题。我在 WSL 中运行
ifconfig并复制 IP 并将其添加到我的主机文件中。这可行,但现在我需要在每次重新启动时重新配置它,因为 IP 不断变化。
标签: windows-subsystem-for-linux wsl-2 hosts