docker从容器内部访问外部localhost主机ip [windows]

问题描述

我正在docker容器中运行Nginx服务器,并且在Nginx.conf文件中,我需要使用不同的端口访问某些地址(目前为localhost)。

当前我要输入127.0.0.1地址,它是Nginx容器的本地主机地址。

所以我需要替换它。

这里是Nginx.conf

http {
    upstream allbackend {
        #ip_hash;
        server 127.0.0.1:9000; <- this is a container localhost
        server 127.0.0.1:9001;     
        server 127.0.0.1:9002;
        server 127.0.0.1:9003;
    }    

    server {
        listen 80;
        location / {
            proxy_pass http://allbackend/;
        }

        location /admin {
            return 403;
        }
    }
}
events {}

server指令中,如何连接到外部localhost

我现在在容器的日志中得到此错误

2020/10/31 14:00:34 [error] 103#103: *11 connect() Failed (111: Connection refused) while connecting to upstream,client: 172.17.0.1,server:,request: "GET / HTTP/1.1",upstream: "http://127.0.0.1:9003/",host: "localhost:4000"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)