You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL Ubuntu 22.04环境下配置虚拟主机my-local.dev指向localhost:3000无效求助

WSL Ubuntu 22.04环境下配置虚拟主机my-local.dev指向localhost:3000无效求助

大家好,我在WSL Ubuntu 22.04环境下配置虚拟主机时碰到了问题,想请各位帮忙排查下哪里出了问题!

我的目标

我想要实现的效果是:在浏览器访问 http://my-local.dev 时,能自动解析到 http://localhost:3000。

我的配置情况

我当前用的是Windows 11 + WSL(Ubuntu 22.04)环境,以下是我做的所有配置操作:

1. /etc/hosts 映射配置

我在hosts文件里添加了对应域名映射:

127.0.0.1       localhost
127.0.0.1       my-local.dev

2. Nginx 虚拟主机配置

  • 查看sites-available目录的文件:
    执行 ls /etc/nginx/sites-available 得到输出:
default
my-local.dev.config
  • 查看sites-enabled目录(已创建软链接):
    执行 ls /etc/nginx/sites-enabled 得到输出:
default
my-local.dev.config -> /etc/nginx/sites-available/my-local.dev.conf
  • 虚拟主机配置文件 my-local.dev.config 的具体内容:
server {
listen 80;
server_name my-local.dev;

location / {
    proxy_pass http://localhost:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}
  • 配置有效性验证:执行 sudo nginx -t 检查配置,结果显示正常:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

当前现象

  • 直接在浏览器访问 http://localhost:3000,可以正常解析并打开服务,没有问题;
  • 但访问 http://my-local.dev 时,却无法达到预期的解析效果,没法正常访问到目标服务。

有没有朋友遇到过类似的问题?或者能帮我看看哪里配置疏漏了吗?

备注:内容来源于stack exchange,提问作者Gogs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 11:33:03