我的docker container kong响应"从上游服务器收到无效响应"

时间:2017-12-28 10:05:08

标签: tomcat docker curl containers kong

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

我的应用程序在端口8811上的tomcat服务器上的另一个容器上运行(端口fwd从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机器使用以下API配置,

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

当我卷曲访问我的示例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容器没有给出正确答案?

1 个答案:

答案 0 :(得分:2)

经过一些试验和测试,我能够弄清楚它失败的原因。

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

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'

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

相关问题