diff --git a/docs/proposals/session-persistence.md b/docs/proposals/session-persistence.md index 85f42b8a6c..1908fd264b 100644 --- a/docs/proposals/session-persistence.md +++ b/docs/proposals/session-persistence.md @@ -1,7 +1,7 @@ # Enhancement Proposal-4051: Session Persistence for NGINX Plus and OSS - Issue: https://github.com/nginx/nginx-gateway-fabric/issues/4051 -- Status: Provisional +- Status: Implementable ## Summary @@ -18,8 +18,180 @@ 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=