首页 > 解决方案 > 尝试访问我的主机文件中设置的本地 IP 地址时出现 ERR_CONNECTION_REFUSED

问题描述

设置:

MACHINE_A 正在运行多个 docker 容器,包括一个 dockerized ember 服务器和一个 dockerized nginx 服务器。机器的本地ip地址是192.168.50.46。它的主机文件已被修改为包括:

127.0.0.1   localhost
127.0.0.1   sub.domain.localhost

nginx 服务器代理来自sub.domain.localhost我们的 dockerized ember 服务器的请求:

location = / {
  proxy_pass http://host.docker.internal:4200;
  error_page 404 500 502 503 504 =200 /index.html;
}

MACHINE_B 在同一个网络上。它的主机文件已被修改为包括:

192.168.50.46   sub.domain.localhost

什么有效:

在 MACHINE_A 上,我可以输入127.0.0.1:4200localhost:4200进入 chrome 上的 url 栏,它将运行我的应用程序。我也可以输入sub.domain.localhost,它会工作。

在 MACHINE_B 上,我可以进入192.168.50.46:4200url 栏,它将运行应用程序。

什么不起作用:

在 MACHINE_B 上,如果我输入,sub.domain.localhost我会收到 ERR_CONNECTION_REFUSED 错误。

问题:

为什么?我们能做些什么吗?

标签: dockerlocalhosthosthosts-file

解决方案


推荐阅读