Sessions across servers
This page is for infrastructure teams in public bodies that run an Exponential site on more than one web server. It answers where sessions are kept, the two ways to keep signed-in editors signed in across servers, what happens to them when a server fails, and which session settings matter. The references are Sessions and Several web nodes.
Contents
- Where sessions are kept
- Two ways to work across servers
- What a failed server means
- Settings that matter
- Checklist
Where sessions are kept
A session keeps one browser signed in. site.ini [Session] Handler decides where it is kept:
| Handler | Where | Several servers |
|---|---|---|
empty (default): ezpSessionHandlerPHP | PHP's own session storage, usually files on the server | each server knows only its own sessions |
ezpSessionHandlerDB | the ezsession table of the site's database | every server sees every session |
Anonymous visitors usually have no session at all; this matters for editors and other signed-in users.
Two ways to work across servers
Sessions in the database. Set the handler in settings/override/site.ini.append.php:
[Session]
Handler=ezpSessionHandlerDBEvery node reads the same table, so the load balancer may send a user to any node. A further benefit for public bodies: Setup > Sessions can then list and remove sessions, for example to sign out a suspected compromised account at once (Sessions). With the default handler that page cannot list or remove sessions one by one; it shows who signed in recently instead.
Keep each user on one node. A balancer that routes by the session cookie keeps a user on the node that holds the
session. [Session] CookieAlwaysAddToHttpResponse=enabled sends the session cookie with every response once a session
runs, for such a balancer; those responses go out with Cache-Control: private
(Security and audit).
| Sessions in the database | Session affinity | |
|---|---|---|
| Balancer configuration | none | routing by cookie |
| A node fails | users stay signed in | its users are signed out |
| Setup > Sessions lists and removes sessions | yes | no |
| Load on the database | one more table in use | none extra |
What a failed server means
With affinity, a failed node signs its users out: editors lose unsaved form input of the moment, but drafts that were stored stay in the database (My drafts and my pending items). With sessions in the database, the next request goes to another node and the user carries on. For a site where editors must keep working during an incident, choose the database handler.
Settings that matter
Setting (site.ini [Session]) | Default | Meaning |
|---|---|---|
SessionTimeout | 31104000 (360 days) | a session ends this many seconds after its last use |
CookieSecure | auto | Secure cookie over HTTPS; behind a balancer that terminates TLS it needs X-Forwarded-Proto from a trusted proxy |
CookieHttponly | true | the cookie is not readable by scripts |
CookieSameSite | Lax | not sent with cross-site requests |
A shorter SessionTimeout for the administration may be a requirement of your security policy; set it in the
administration siteaccess's settings. Logging out ends the session for good under every handler, and a password
change ends other sessions ([PasswordSettings] EndOtherSessions=enabled)
(Security standards).
Checklist
- To do: With several servers:
ezpSessionHandlerDB, or session affinity agreed with the network team. - To do: The trade-off for a failed node is documented.
- To do:
TrustedProxies[]lists the balancer, so theSecureflag is right behind TLS termination. - To do:
SessionTimeoutmatches your security policy.
Related pages
- Availability index of this folder
- Several web servers behind a load balancer
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.