【问题标题】:NGINX & Kestrel 502 Response (111: Connection Refused)NGINX & Kestrel 502 响应(111:连接被拒绝)
【发布时间】:2019-02-16 10:03:41
【问题描述】:

我在 docker 容器中设置了 NGINX,它可以正确地提供静态内容,所以那里没有问题。我将其配置为代理以指向我的 Mac 上的 Kestrel。 Kestrel 在端口 5000 上的响应很好(通过 Curl 检查),但由于某些奇怪的原因 NGINX 无法连接到它。

日志说:

15 connect() 在连接到时失败(111:连接被拒绝) 上游,客户端:172.17.0.1,服务器:[OMITTED],请求:“GET /api/values/5000 HTTP/1.1",上游: "http://127.0.0.1:5000/api/values/5000"

我的 NGINX 配置:

      location / {
        proxy_pass         http://dotnet;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}
upstream dotnet {
    zone dotnet 64k;
    server 127.0.0.1:5000;
}

【问题讨论】:

标签: nginx asp.net-core kestrel-http-server kestrel


【解决方案1】:

由于 nginx 在您的容器中运行,因此 127.0.0.1 是容器本地的,而不是运行它的主机。

您需要更改 IP 地址以匹配容器视为主机的地址(请参阅此处:https://forums.docker.com/t/accessing-host-machine-from-within-docker-container/14248/4)

另外,不要忘记打开防火墙上的端口 :-)

【讨论】:

    猜你喜欢
    • 2014-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2020-10-26
    • 2022-01-11
    相关资源
    最近更新 更多