【问题标题】:curl: (7) Failed to connect to localhost port 8090: Connection refusedcurl: (7) 无法连接到 localhost 端口 8090:连接被拒绝
【发布时间】:2017-05-12 19:46:46
【问题描述】:

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

我有一个带有 NGINX 的 docker 容器,充当反向代理。 Docker for Windows 版本 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

(简单的 HTML 站点,只有简单 html 的单页,托管在 IIS 上,授予所有人匿名访问权限。)

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,则相同的配置有效。

谢谢。

【问题讨论】:

    标签: curl nginx docker reverse-proxy


    【解决方案1】:

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

    【讨论】:

    • 谢谢。有效。我没有使用 localhost,而是使用了主机名,效果很好。修改 conf 详细信息如下:'upstream mysite { server hostname:8090; }''服务器{听0.0.0.0:80; server_name 本地主机;位置 / { proxy_pass mysite; } }'
    • 我已经尝试过了,但它似乎不起作用。我也尝试使用 0.0.0.0 代替主机名。 stackoverflow.com/questions/50976913/….
    • 我在 nginx 中没有 docker 时遇到了类似的问题,这解决了我的问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2019-02-19
    • 2019-01-07
    • 1970-01-01
    • 2021-05-23
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多