【问题标题】:My docker container kong responds with "An invalid response was received from the upstream server"我的 docker 容器 kong 响应“从上游服务器收到无效响应”
【发布时间】:2017-12-28 10:05:07
【问题描述】:

我有 kong 在我的本地 linux 机器上的 8000 和 8001 端口上运行,我也有 kong,它在我的 docker 容器中的一个 5000 和 5001 端口上运行。

我的应用程序在 Tomcat 服务器上的另一个容器上运行,端口为 8811(端口从 8811 到 8080)

我已经使用以下 API 配置配置了我的 kong 容器,

curl -i -X POST \
 --url http://localhost:5001/apis/ \
 --data 'name=sample' \
 --data 'uris=/samplewar' \
 --data 'upstream_url=http://localhost:8811/sample/hello'

和我的 linux 机器 kong 以及以下 API 配置,

curl -i -X POST \
 --url http://localhost:8001/apis/ \
 --data 'name=sample' \
 --data 'uris=/samplewar' \
 --data 'upstream_url=http://localhost:8811/sample/hello' 

当我通过 curl 访问我的示例 API 时,我看到来自 Kong 容器的以下错误响应,

curl -i -X GET --url http://localhost:5000/samplewar
HTTP/1.1 502 Bad Gateway
Date: Thu, 28 Dec 2017 08:25:26 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/0.11.2

An invalid response was received from the upstream server

如果我尝试在我的 linux 机器中调用相同的 API,我会看到以下成功响应。

curl -i -X GET --url http://localhost:8000/samplewar

HTTP/1.1 200 OK
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 311
Connection: keep-alive
Server: Apache-Coyote/1.1
Date: Thu, 28 Dec 2017 08:25:33 GMT
X-Kong-Upstream-Latency: 2
X-Kong-Proxy-Latency: 0
Via: kong/0.11.2

<html>
<head>
<title>Sample Application Servlet Page</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td>
<img src="images/tomcat.gif">
</td>
<td>
<h1>Sample Application Servlet</h1>
This is the output of a servlet that is part of
the Hello, World application.
</td>
</tr>
</table>
</body>
</html>

这里有什么问题?为什么我的 Kong 容器没有给出正确的响应?

【问题讨论】:

标签: tomcat docker curl containers kong


【解决方案1】:

经过一些试验和测试,我能够找出失败的原因。

由于这里的场景是Kong在一个容器中运行,而Tomcat服务器上的示例应用程序在另一个容器中,因此kong容器中的upstream_url配置必须使用tomcat容器的ip和端口进行配置。 (即“upstream_url=http://172.17.0.4:8080/sample/hello”,其中 172.17.0.4 是我的 tomcat 容器的 IP 地址)

curl -i -X POST \
--url http://localhost:5001/apis/ \
--data 'name=sample' \
--data 'uris=/samplewar' \
--data 'upstream_url=http://172.17.0.4:8080/sample/hello'

这解决了这个问题,但是我不太确定这是否是最佳解决方案。

【讨论】:

  • 遇到了同样的问题。对于使用 kong 容器上游其他容器服务的每个人,请检查以下内容,请确保 kong 和所有其他容器必须是同一个 docker 网络。意味着您必须在启动其他容器时传递参数 '--network=kong-net'。或者只是从 kong 中删除 --network=kong-net' (这将使 kong 从默认的 docker 网络开始)
  • 您是如何获得ip and port of the tomcat container 的?我在我创建的服务的日志部分尝试了 docker 桌面应用程序中给出的 ip,但它不起作用。我在windows10上,我的docker在localhost:8000上运行,我的服务在localhost:4100上运行。
猜你喜欢
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 2012-04-07
  • 2019-03-17
  • 2015-10-09
  • 2023-03-20
  • 1970-01-01
  • 2023-03-17
相关资源
最近更新 更多