在Windows上将Dockererized Kong给出“从上游服务器接收到无效响应” [英] Dockererized Kong on windows giving "An invalid response was received from the upstream server"

查看:1734
本文介绍了在Windows上将Dockererized Kong给出“从上游服务器接收到无效响应”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Dockerized Kong从REST端点获取数据时出现从上游服务器收到无效响应错误时,请帮我。

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服务

Kong请求添加API:

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'

通过Kong转发请求:

Forward request through Kong :

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

我在通过Kong转发请求时出错:

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

请帮助我解决此问题。

谢谢,
Kamal

Thanks, Kamal

推荐答案

我认为您遇到了经典的IP /主机问题当您开始使用Docker时。这里的关键是您必须注意使您被docker化的Kong能够从docker容器内到达您的 localhost 。这里的问题是(很可能)是Kong(在docker内部)试图访问 http:// localhost:8080 。但是对于Kong来说,这就是它自己运行的容器。

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.

要进行这种测试,您必须找到本地计算机的IP地址并添加作为 upstream_url 。根据计算机的位置,在家庭网络中还是在企业网络中,将类似于 10.xyz 192.168.xy 。命令 ifconfig (macOS)或 ipconfig (Windows)将帮助您找到该地址。通过使用此IP,Kong现在将能够解析本地计算机的端口8080,而不是转到其自己的端口8080。

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.

请注意,这意味着您每次更改计算机的IP地址时,都需要在Kong中重新配置API。

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取决于笔记本电脑的使用情况,还是使用DHCP或类似的设备。 ; dr:上游URL必须是使Kong能够解析从Docker容器内部看到的目标的URL

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

这篇关于在Windows上将Dockererized Kong给出“从上游服务器接收到无效响应”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆