向Kong添加服务
简介
Kong 管理的上游API和微服务,被称为 Service。 在开始向 Service 发出请求之前,需要为其添加一个 Route。 Route 指定请求在到达 Kong 后如何发送到 Service。 一个 Service 可以有多个 Route.
添加服务
添加路由
在hosts一栏输入:example.com,并回车,不回车 Konga 会认为未输入。
通过 Kong 转发请求
curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host: example.com'
输出:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Date: Thu, 18 Mar 2021 07:51:45 GMT
Set-Cookie: __cfduid=d95fe51f4c5a2051e0ddccd71da8dd4111616053904; expires=Sat, 17-Apr-21 07:51:44 GMT; path=/; domain=.mockbin.org; HttpOnly; SameSite=Lax
Vary: Accept-Encoding
Via: kong/2.3.3
CF-Cache-Status: DYNAMIC
cf-request-id: 08e5eabe550000363099a7b000000001
Report-To: {"max_age":604800,"group":"cf-nel","endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=Kh3eSAw34ODjNSIYD1hSbuCGblVaYUrXaJxRyFZ3xTj3Al%2BzwoRglEwsDevLzRdmb44fXKl%2BQl7wbuyw9RIjJL2Gu4%2Fgim8TGhH3kw%3D%3D"}]}
NEL: {"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 631ce0aa2f273630-LAX
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
X-Kong-Upstream-Latency: 553
X-Kong-Proxy-Latency: 166
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Mockbin by Kong</title>......
成功的响应意味着 Kong 现在将对 http//localhost:8000 的请求转发到我们配置的URL,并将响应转发给我们。