在 Ubuntu WSL2 上连接到本地主机的问题 [英] Problem with connecting to localhost on Ubuntu WSL2

查看:41
本文介绍了在 Ubuntu WSL2 上连接到本地主机的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地为 django 项目设置了 Apache2 服务器,并且运行良好.问题是,在休息一天后,我回到它并尝试进入服务器,但不知何故我无法连接到它,即使在检查 apache 服务是否正在运行并重新加载配置以确保之后也是如此.我无法从本地主机和任何其他本地标签访问它.

I set up locally Apache2 server for django project, and it worked perfectly well. The problem is that after one day off i got back to it and tried getting on server, and somehow i couldn't connect to it, even after checking if apache service is running, and reloading configuration just to be sure. I couldn't access it from localhost, and any other local tag.

所以在那之后我尝试使用 django runserver 命令.服务器正在运行,但我也无法访问它.2天前,它工作没有任何问题.我在 WSL 3 上使用 Ubuntu,在 Windows 上我可以毫无问题地运行服务器.尝试 ping localhost 并得到 100% 的包丢失.

So after that i tried with django runserver command. Server was running, but i couldn't get on it as well. 2 days before, it worked without any issues. I'm using Ubuntu on WSL 3, and on windows i can run server without any problems. Tried pinging localhost and got 100% package loss.

我当时所做的是通过擦除所有数据重新启动整个 Ubuntu 服务.设置系统后一切正常.问题是这是第二次出现这个问题,上次我以同样的方式摆脱它,只是通过删除所有数据重新启动整个 Ubuntu.第二次设置完所有内容并运行服务器后,我尝试重新启动计算机以检查是否发生此问题,但在 Windows 重新启动后,它起作用了.

What i did then was restarting whole Ubuntu service with wiping all data. After setting up system everything worked again. The thing is that this is second time that this problem is occuring, and last time i get rid of it the same way, just restarting whole Ubuntu with removing all data. Second time after setting everything up and running server i tried restarting my computer to check if this problemm occurs, after windows restart, but it worked.

我刚刚发现了一些非常奇怪的事情.我试着关闭我的电脑,然后再打开它.我无法连接到服务器,但重新启动它后,我可以像什么也没发生一样连接.试了几次,每次重启后都可以连接,但是关掉再打开就连接不上了.

I just discovered something really strange. I tried turning off my computer, and then turning it on. I could not connect to server, but after rebooting it i can connect like nothing happens. Tried it few times and literally every time after reboot i can connect, but after turning it off, and turning on i can't connect.

推荐答案

有关详细信息,请参阅此答案.但是,还有更多细节:

See this answer for more details. Some more details, however:

恢复的快捷方式应该正在运行:

A shortcut to recovery should be running:

wsl --shutdown

之后,WSL 的 localhost 端口自动映射应该会恢复正常.

After that, WSL's localhost port auto-mapping should be back to normal.

但要获得更持久的修复,请尝试禁用 Windows 快速启动.此设置导致 Windows 进入伪休眠状态,这似乎是本地主机故障的最大罪魁祸首.

But for a more permanent fix, try disabling Windows Fast Startup. This setting is causing Windows to pseudo-hibernate, which seems to be the biggest culprit in the localhost breakdown.

这篇关于在 Ubuntu WSL2 上连接到本地主机的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆