【发布时间】:2018-04-15 22:12:03
【问题描述】:
我正在尝试使用带有 nginx 的 docker 容器作为其他 docker 容器的反向代理,并且在基本位置 '/' 以外的位置上不断收到“错误网关”。
我有以下服务器块:
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
【问题讨论】:
-
现在我贴出来,我看到路径“游戏”被传递到上游服务器,那部分不应该被传递。任何想法如何处理?顺便说一句,在我想使用它的场景中,我希望它根据传入的服务器名称/http 标头代理到不同的服务。
-
我使用了错误的端口。