From 187da0e8dfae2c57fa44c28ae07eb41159393f1d Mon Sep 17 00:00:00 2001 From: salonichf5 <146118978+salonichf5@users.noreply.github.com> Date: Tue, 4 Nov 2025 21:05:05 -0700 Subject: [PATCH 1/2] detailed design for session persistence --- docs/proposals/session-persistence.md | 159 ++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/docs/proposals/session-persistence.md b/docs/proposals/session-persistence.md index 85f42b8a6c..054a827971 100644 --- a/docs/proposals/session-persistence.md +++ b/docs/proposals/session-persistence.md @@ -18,8 +18,167 @@ Enable NGINX Gateway Fabric to support session persistence for both NGINX Plus a - Extend session persistence support to TLSRoutes or other Layer 4 route types. - Supporting the `sameSite` cookie directive for NGINX Plus session persistence, which may be considered in the future as the Gateway API `sessionPersistence` specification evolves. +## Introduction + +For NGINX OSS, session persistence is enabled by setting `loadBalancingMethod: ip_hash` on UpstreamSettingsPolicy, which adds the `ip_hash` directive to upstreams and provides IP-based affinity. +For NGINX Plus, session persistence defined on `HTTPRouteRule/GRPCRouteRule` is translated into sticky cookie upstream configuration with secure, httpOnly, host-only cookies and a path derived from HTTPRoute matches (or defaulted for GRPCRoutes), so sessions stick to a chosen backend. + +### Understanding the NGINX directives + +**ip_hash** + +The [ip_hash](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash) directive enables session persistence by routing requests from the same client IP address to the same upstream server. It uses the client’s IP address as a hash key to determine the target server, ensuring consistent routing for users behind a single IP. If the chosen server becomes unavailable, NGINX automatically selects the next available upstream server. + +Syntax: + +```bash +ip_hash; +``` + +**sticky (cookie method)** + +The [sticky](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky) directive enables session persistence using a cookie to identify the upstream server handling a client’s session. When configured with the cookie parameter, NGINX sends a cookie token in the client response in a `Set-Cookie` header, allowing the browser to route subsequent requests with that cookie to the same upstream server. + +Syntax: + +```bash +sticky cookie name [expires=time] [domain=domain] [httponly] [samesite=strict|lax|none|$variable] [secure] [path=path]; +``` + +Key Parameters: +cookie – Defines the session cookie name. +expires=