OStack程序员社区-中国程序员成长平台

标题: curl:(7)无法连接到本地主机端口8090:连接被拒绝 [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-3 10:12
标题: curl:(7)无法连接到本地主机端口8090:连接被拒绝

需要帮忙。一直在尝试解决此问题,但找不到答案,或者我没有遇到任何问题。

我有一个带有NGINX的docker容器,充当反向代理。适用于Windows的Docker版本1.12.5(9503)。

upstream mysite {
    server 127.0.0.1:8090;
    #server localhost:8090; (have also tried this option)
}

server {
    listen 0.0.0.0:80;
    server_name  localhost;

    location / {
        proxy_pass http://mysite;
    }
}

在上面的代码中,localhost:8090是在我的主机上的IIS上托管的网站的URL。当我在NGINX上访问URL时,出现以下错误
2016/12/27 08:11:57 [error] 6#6: *4 no live upstreams while connecting to upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://googlesite/", host: "localhost"
172.17.0.1 - - [27/Dec/2016:08:11:57 +0000] "GET / HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0" "-"

试图访问主机上的URL

(simple HTML site, single page with only simple html, hosted on IIS with anonymous access granted to all.)


curl localhost:8090

出现以下错误:
curl: (7) Failed to connect to localhost port 8090: Connection refused

Docker和NGINX的新手。是否想知道是否可以访问主机上的URL?如果是,那我在哪里错了。

如果我使用google.co.in而不是127.0.0.1:8090,则可以使用相同的配置。

谢谢。



Best Answer-推荐答案


在docker容器内,localhost127.0.0.1指的是容器本身。为了访问与您的容器一起运行dockerd的主机,您必须通过其公用主机名/IP引用该主机,就好像该主机是网络上的另一台计算机一样。

关于curl7)无法连接到本地主机端口8090:连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41363529/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4