gpt4 book ai didi

Docker nginx反向代理给出 "502 Bad Gateway"

转载 作者:IT老高 更新时间:2023-10-28 21:22:24 25 4
gpt4 key购买 nike

我正在尝试使用带有 nginx 的 docker 容器作为其他 docker 容器的反向代理,并且在基本位置 '/' 以外的位置上不断收到“错误网关”。

我有以下服务器 block :

server {

listen 80;

location / {
proxy_pass "http://game2048:8080";
}

location /game {
proxy_pass "http://game:9999";
}

}

它适用于 http://localhost 但不适用于 http://localhost/game 在浏览器中提供“Bad Gateway”,而这在 nginx 容器上:

[error] 7#7: *6 connect() failed (111: Connection refused) 
while connecting to upstream, client: 172.17.0.1, server: ,
request: "GET /game HTTP/1.1", upstream: "http://172.17.0.4:9999/game",
host: "localhost"

我使用官方的 nginx docker 镜像,并在上面放上我自己的配置。您可以对其进行测试并在此处查看所有详细信息: https://github.com/jollege/ngprox1

有什么想法吗?

注意:我在 docker 主机上设置了本地主机名条目以匹配这些名称:

127.0.1.1       game2048
127.0.1.1 game

最佳答案

我修好了!我在 nginx 配置中的不同服务器 block 中设置了服务器名称。请记住使用 docker 端口,而不是主机端口。

server {

listen 80;
server_name game2048;

location / {
proxy_pass "http://game2048:8080";
}

}

server {

listen 80;
server_name game;

location / {
# Remember to refer to docker port, not host port
# which is 9999 in this case:
proxy_pass "http://game:8080";
}

}

github repo 已更新以反射(reflect)修复,旧的自述文件位于 ./README.old01.md 下。

当我仔细地向别人提出问题时,我通常会找到答案。你知道那种感觉吗?

关于Docker nginx反向代理给出 "502 Bad Gateway",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47091356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com