Reputation: 2934
I create a basic express app
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);
Then I add following entrie in c:\windows\system32\drivers\etc\hosts
127.0.0.1 custom.local
Then I shutdown wsl wsl --shutdown
and re-open to start my express app.
If I check hosts file from WSL (cat /etc/hosts
), I got following result
# 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
Then I go to http://custom.local
trough chome in windows. But it's doesn't display my express app. (If i run express on windows instead of wsl it's work well).
What's wrong on my hosts file ?
Upvotes: 5
Views: 15507
Reputation: 2934
Finally I found a solution on github: https://github.com/microsoft/WSL/issues/5728#issuecomment-917295590
Instead declare domain like that
127.0.0.1 custom.local
I do as follow:
127.0.0.1 custom.local
::1 custom.local localhost
Upvotes: 10
Reputation: 11
Previously, I had my WSL in version 1 and everything worked fine. Then I decided to upgrade to WSL 2 and - similar to many others - I lost internet connection. Thankfully, I could easily bring it back by running:
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
Apparently, it was just a DNS issue. I could live with that. However, then I restarted my WSL and the nameserver was set back to 172.31.208.1. So I decided to do exactly what was written in the comments in /etc/resolv.conf:
And ran the following lines:
sudo bash -c 'echo "[network]" > /etc/wsl.conf' sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf' I was proud that I resolved the issue so elegantly until I restarted my WSL again. Now, resolv.conf was in red and not accessible from Ubuntu. When I tried to access it from Windows, I saw just an empty file.
Expected behavior After restarting WSL, resolv.conf keeps the user-defined values.
Actual behavior After restarting WSL, resolv.conf is empty or not accessible at all.
Upvotes: 0