Proxying is when Kong Gateway matches an HTTP request with a Route and forwards the request. This page explains how Kong Gateway handles proxying.
sequenceDiagram actor Client participant Gateway as Kong Gateway participant Router participant Plugins as Plugins participant LoadBalancer as Load balancer participant UpstreamService as Upstream service Client->>Gateway: Sends HTTP request or L4 connection Gateway->>Router: Evaluates incoming request against Routes Router->>Router: Orders Routes by priority Router->>Gateway: Returns highest priority matching Route Gateway->>Plugins: Executes plugins the `access` phase Gateway->>LoadBalancer: Implements load balancing capabilities LoadBalancer->>LoadBalancer: Distributes request across upstream service instances LoadBalancer->>UpstreamService: Forwards request to selected instance UpstreamService->>Gateway: Sends response Gateway->>Plugins: Executes plugins in the `header_filter` phase Gateway->>Client: Streams response back to client
Kong Gateway handles proxying in the following order:
- Kong Gateway listens for HTTP traffic on its configured proxy port(s) (
8000
and8443
by default) and L4 traffic on explicitly configuredstream_listen
ports. - Kong Gateway evaluates any incoming HTTP request or L4 connection against the Routes you have configured and tries to find a matching one. For more details about how Kong Gateway handles routing, see the Routes entity.
- If multiple Routes match, the Kong Gateway router then orders all defined Routes by their priority and uses the highest priority matching Route to handle a request.
- If a given request matches the rules of a specific Route, Kong Gateway runs any global, Route, or Gateway Service plugins before it proxies the request.
Plugins configured on Routes run before those configured on Services.
These configured plugins run their
access
phase. For more information, see plugin contexts. - Kong Gateway implements load balancing capabilities to distribute proxied requests across a pool of instances of an upstream service.
- Once Kong Gateway has executed all the necessary logic (including plugins), it’s ready to forward the request to your upstream service.
This is done via Nginx’s
ngx_http_proxy_module
. - Kong Gateway receives the response from the upstream service and sends it back to the downstream client in a streaming fashion.
At this point, Kong Gateway executes subsequent plugins added to the Route and/or Service that implement a hook in the
header_filter
phase.