Dockererized Kong on windows giving “An invalid response was received from the upstream server”

白昼怎懂夜的黑 提交于 2019-12-12 19:03:18

问题


Please help me as I am getting "An invalid response was received from the upstream server" error on getting the data from REST endpoint using Dockerized Kong.

REST service that I am trying to access using Kong is running on my localhost.

Kong Request to add API :

 curl -i -X POST \
--url http://localhost:8001/apis/ \
--data 'name=ping' \
--data 'upstream_url=http://localhost:8080/v1/employee/ping' \
--data 'hosts=localhost'

Forward request through Kong :

curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host:localhost'

Error that I am getting on forwarding the request through Kong:

[root@c1c865250782 etc]# curl -i -X GET --url http://localhost:8000/ --
header 'Host:localhost'
HTTP/1.1 502 Bad Gateway
Date: Fri, 29 Dec 2017 08:53:40 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

Please help me to solve this issue.

Thanks, Kamal


回答1:


I think you're running into the classic IP/Host issue you get when you start out with Docker. The key here is that you must pay attention to making your dockerized Kong be able to reach your localhost from inside the docker container. The issue here is (most likely) that Kong (inside docker) tries to access http://localhost:8080. But for Kong, that's the container it is running on itself.

To do this kind of testing, you will have to find the IP address of your local machine and add that as the upstream_url. Depending on where your machine is, in a home network, or in a corporate network, that will be something like 10.x.y.z, or 192.168.x.y. The command ifconfig (macOS) or ipconfig (Windows) will help you find that address. By using this IP instead, Kong will now be able to resolve your local computer's port 8080, instead of going to its own port 8080.

Please note that this means that you need to reconfigure the API in Kong each time you change IP address of your machine. Depending on whether it's a laptop, or if you use DHCP or such, this will be more or less often.


tl;dr: The upstream URL has to be an URL which enables Kong to resolve the target as seen from inside the Docker container.



来源:https://stackoverflow.com/questions/48020283/dockererized-kong-on-windows-giving-an-invalid-response-was-received-from-the-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!