我的 docker 容器 kong 响应 "An invalid response was received from the upstream server"

My docker container kong responds with "An invalid response was received from the upstream server"

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

我的应用程序 运行 在端口 8811 上 tomcat 服务器上的另一个容器上(端口从 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 machine 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 容器没有给出正确的响应?

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

由于此处的场景是 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'

这解决了问题,但我不太确定这是否是最佳选择。