简体   繁体   English

在Windows上进行Dockererized Kong操作,显示“从上游服务器收到无效响应”

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

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. 请在使用Dockerized Kong从REST端点获取数据时收到“从上游服务器收到无效响应”错误消息,请为我提供帮助。

REST service that I am trying to access using Kong is running on my localhost. 我试图使用Kong访问的REST服务正在本地主机上运行。

Kong Request to add API : 要求添加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 : 通过Kong转发请求:

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

Error that I am getting on forwarding the request through Kong: 我通过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 谢谢,卡马尔

I think you're running into the classic IP/Host issue you get when you start out with Docker. 我认为您开始使用Docker时遇到的经典IP /主机问题。 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 . 这里的关键是您必须注意使您被docker化的Kong能够 docker 容器内部访问localhost The issue here is (most likely) that Kong (inside docker) tries to access http://localhost:8080 . 这里的问题是(很可能)是Kong(在docker内部)试图访问http://localhost:8080 But for Kong, that's the container it is running on itself. 但是对于Kong来说,这就是它自己运行的容器。

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 . 要进行这种测试,您将必须找到本地计算机的IP地址并将其添加为upstream_url Depending on where your machine is, in a home network, or in a corporate network, that will be something like 10.xyz , or 192.168.xy . 根据机器的位置,在家庭网络中还是在企业网络中,将类似于10.xyz192.168.xy The command ifconfig (macOS) or ipconfig (Windows) will help you find that address. 命令ifconfig (macOS)或ipconfig (Windows)将帮助您找到该地址。 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. 通过使用此IP,Kong现在将能够解析本地计算机的端口8080,而不用转到其自己的端口8080。

Please note that this means that you need to reconfigure the API in Kong each time you change IP address of your machine. 请注意,这意味着您每次更改计算机的IP地址时都需要在Kong中重新配置API。 Depending on whether it's a laptop, or if you use DHCP or such, this will be more or less often. 根据是笔记本电脑,还是使用DHCP或类似的设备,这种情况或多或少会经常发生。


tl;dr: The upstream URL has to be an URL which enables Kong to resolve the target as seen from inside the Docker container . tl; dr:上游URL必须是使Kong能够解析从Docker容器内部看到的目标的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM