Load balancing Strapi with HAProxy

When one Strapi instance is no longer enough, HAProxy can terminate TLS and spread traffic across several instances with health checks on /_health. The harder work is confirming what every instance must share, such as the database, uploads and signing secrets.

On this page

When load balancing Strapi with HAProxy makes sense

You are running a Strapi API or admin panel under growing traffic, or you need to restart and upgrade Strapi without taking the site offline. In that situation HAProxy can terminate TLS and distribute requests across several Strapi instances, sending traffic only to instances that pass health checks on /_health. The real effort is not the HAProxy configuration itself. It lies in shared state: every instance must read the same database, upload storage, secrets and configuration, and any file or cache written on one node must be visible to the others before you add a second instance.

A load balancer is one more layer to operate. It needs its own certificates, configuration reviews, monitoring, logging and upgrade cycle, and it becomes a single point of failure unless you run it as a pair. Before you commit, confirm whether a single, well-sized Strapi instance backed by a managed PostgreSQL or MySQL service already meets your availability goals. For many internal content workloads, one instance with a tested restart procedure and a managed database is enough, and a load balancer only adds risk.

Ask three questions before you design the topology. Does your traffic pattern or your restart window actually require more than one node? Can your upload provider and session handling work when two instances serve the same user? Who on your team will own HAProxy changes after go-live? If the answers are unclear, a short review of your current deployment is cheaper than a multi-node setup that nobody can troubleshoot at 2 a.m. Confirm the Node.js and database versions you plan to use against the Strapi installation requirements before you size the nodes.

HAProxy settings to decide before configuring Strapi backends

This table compares the HAProxy decisions that shape a multi-instance Strapi setup, from TLS termination to forwarded headers and timeouts. Read each row as a choice to make before writing configuration, and confirm exact directive names and syntax against the HAProxy version you run. The main takeaway is that the health check, affinity and header decisions affect how Strapi behaves for editors and end users, not only how traffic is spread.

DecisionOption and when it fitsWhat it affectsConfirm before go-live
TLS terminationTerminate at HAProxy when the load balancer holds certificates and forwards plain HTTP to Strapi on a private networkCertificate renewal location, plaintext traffic inside the network, and where HSTS and redirects are setWhether backend traffic must also be encrypted under your network policy
Health check pathUse the Strapi health endpoint on /_health so HAProxy only routes to instances that report readyRemoval of failed instances from rotation and how quickly a restarting instance rejoinsExpected status code and the check interval for your HAProxy version
Health check thresholdsSet rise and fall counts so one slow response does not drop an instance, while a sustained failure doesFlapping during deploys, database slowdowns and rolling restartsCurrent threshold directive names and default values in your release
Balancing algorithmRound robin suits instances with similar capacity and short requests; least connections suits mixed upload and admin trafficSpread of long uploads and media-heavy requests across instancesAlgorithm keywords supported by your HAProxy build
Session affinityPin clients to one instance when a stateful session or cached admin state lives on that node; avoid it if sessions are sharedUneven load, failover behavior and how a drained instance hands off usersWhether Strapi sessions and tokens are stored in the shared database for your setup
Timeouts for uploads and admin requestsRaise client and server timeouts on routes that carry media uploads or long content imports, and keep API routes tighterFailed uploads, dropped admin saves and hung connections under loadMaximum upload size on Strapi and matching limits on HAProxy
Forwarded client headersSend X-Forwarded-For, X-Forwarded-Proto and Host to Strapi and configure Strapi to trust the proxyClient IP in logs and rate limits, generated absolute URLs, and secure cookie behaviorProxy trust and server URL settings described in the Strapi security and deployment docs
Shared state between instancesKeep uploads on a shared provider, sessions in the shared database and secrets identical on every nodeWhether a request succeeds on any instance and whether a restart loses dataStorage provider, database connection limits and identical environment values across nodes

How a request moves from the client through HAProxy to Strapi

A request starts at the browser or API client on the public network and reaches HAProxy, which terminates TLS and adds forwarded headers before passing traffic on. HAProxy sends each request only to Strapi instances that pass their /_health check, and those instances share one database and one upload location on the private backend network. Check that the trust boundary sits where you expect and that every instance points at the same database and upload store.

Request path from client through HAProxy to shared Strapi backends.

What must be shared between Strapi instances

Every instance must point at the same database. Strapi keeps content, content type definitions written through the admin panel, roles, permissions, API tokens and the admin user records in the database, so two nodes connected to different databases will show editors different content and different schemas. Run one PostgreSQL, MySQL, MariaDB or SQLite-free production database that all backends reach, and confirm which database versions your Strapi release supports against the installation requirements before you cut over. Do not use SQLite for a balanced pool, because a file-based database cannot be shared safely across hosts. Schema changes also need care: confirm with your team which instance is allowed to run migrations, since two nodes starting at once against a new schema is a failure mode you should plan out in advance.

Uploads must go to storage that every instance can reach. By default, Strapi's local upload provider writes files to the public/uploads folder on the node that received the request, so a file uploaded through one instance will return a 404 when HAProxy routes the next request for it to another. Use an external upload provider such as an S3-compatible bucket or a provider plugin, and confirm the provider configuration and the default behavior in the Strapi version you run. Also confirm the upload size limits in HAProxy match what Strapi accepts, because a limit set on only one layer produces inconsistent errors.

Signing secrets and keys must match on every instance. Values such as APP_KEYS, API_TOKEN_SALT, ADMIN_JWT_SECRET, JWT_SECRET and TRANSFER_TOKEN_SALT are used to sign or hash admin sessions, end-user tokens and API tokens. If one node holds a different value, a token issued by one instance will be rejected by another, and users will appear to log out at random. Store these in a shared secret manager and inject them identically into each container or process. Scheduled jobs and one-time startup tasks, such as cron tasks defined in your project and bootstrap logic in src/index.js, can also run once per instance unless you gate them, for example by running them in a single designated process. Confirm how your Strapi version handles cron tasks in multi-instance deployments before you rely on the default.

Sticky sessions for the admin panel versus stateless API traffic

Public API requests that carry a token usually do not need session affinity. Each request presents its own credentials, so any healthy instance can answer it, as long as every instance trusts the same secrets and reads the same database. Round-robin or least-connections balancing is a sound starting point for this traffic. The most common failure is intermittent 401 responses caused by one node signing or validating tokens with a different secret, so compare configuration across nodes before you go live.

  • Matching secrets: every instance loads identical signing and salt secrets from the same secret store.
  • Shared database: all instances connect to one external database. Local SQLite files are not a fit for several instances.
  • Shared uploads: media written by one node must be reachable from every node, typically through an external upload provider.
  • Health checks: HAProxy stops sending traffic to any node that fails the /_health check.
  • Safe retries: clients can retry idempotent requests against another node without extra logic.

Before relying on round-robin, confirm that a token issued by one node is accepted by every other node.

Setup sequence for HAProxy in front of Strapi

This sequence takes a Strapi deployment from a single instance to several identical instances behind HAProxy, with TLS terminated at the load balancer and each step checked before the next begins. The result is a pool that keeps serving editors and end users when one instance stops.

  1. Confirm the Strapi version and database

    Confirm the exact Strapi 5 minor version you will run, the Node.js version it targets, and a supported database such as PostgreSQL, MySQL, MariaDB or SQLite. Strapi 5 does not support MongoDB or other NoSQL databases, so this check decides the whole architecture. Your platform or engineering lead signs off on the version pin in your repository. Done means every instance will be built from the same pinned version and a supported database engine is confirmed in writing.

  2. Share the database and upload storage

    Move the database to a server that every Strapi instance can reach over the network, and move uploads to shared object storage or another provider that all instances can read and write. Local disk uploads on one node will break for any user whose request lands on a different instance. Your infrastructure team owns the network rules and storage access, and the Strapi team configures the upload provider. Verify by uploading a file through one instance and confirming a second instance can fetch the file URL.

  3. Align secrets and public URL settings

    Give every instance the same application keys, JWT and API token secrets, and transfer tokens, and set the same public URL so generated links and admin redirects match the load balancer hostname. Store these values in your secrets manager and inject them at start, not in files baked into an image. Developers and the platform team share ownership of this step. Verify by logging in through one instance, then confirming the session is accepted by another instance when you point a test request directly at it.

  4. Expose a working health endpoint

    Confirm that each instance answers on the /_health endpoint with a success response before it is added to the pool. Check the response directly on each host and port, not through the load balancer, so a failing node is identified by name. The platform team writes the probe into the service definition, and the Strapi team confirms the route is reachable from the HAProxy subnet. Done means each backend returns a healthy response on its own address.

  5. Configure TLS termination and backends

    Configure HAProxy to terminate TLS with your certificate, forward plain HTTP to the Strapi backends, and define a backend server list with an HTTP health check against /_health. Set the check interval and failure thresholds in your own environment after testing, since the values depend on your traffic and startup time. The network or platform engineer owns this configuration. Verify by running the HAProxy configuration check, reloading, and seeing every backend marked up in the stats page.

  6. Set forwarded header handling

    Configure HAProxy to add the forwarded protocol and client address headers, and configure Strapi to trust the proxy so it builds correct URLs and treats requests as HTTPS. Without this, Strapi may generate http links for https pages or reject cookies that depend on the secure flag. Confirm the exact proxy trust settings against the Strapi version you pinned. Verify by requesting an admin page and an API response through HAProxy, then checking that returned URLs use the public hostname and https.

  7. Test login and uploads through the balancer

    Run an end-to-end check through HAProxy: sign in to the admin panel, create a test entry, and call a public or authenticated API route. Repeat the requests several times so they land on different instances, and upload a file that a second instance must read. Record which backend served each request in the HAProxy logs. Your QA or platform team runs the test and keeps the results with the change record.

  8. Test failover during live traffic

    Generate steady traffic through HAProxy, then stop one Strapi instance and watch the stats page and client responses. HAProxy should mark that backend down and route requests to the remaining instances, and users should see only brief errors while the health check catches up. Restart the instance and confirm it rejoins the pool once /_health responds again. Done means you have a written record of the observed failure window and the rejoin behavior, and you have agreed on the acceptable result with the business owner.

Security and operations to review before HAProxy goes live

A load balancer in front of Strapi changes where trust, identity and logging live. The cards below cover the decisions that connect HAProxy and the Strapi instances behind it, and the checks to run before production traffic moves.

Block direct access to Strapi instances

If clients can reach a Strapi instance on its own port or address, they bypass HAProxy's TLS termination, header handling and rules. Confirm that only HAProxy can reach each instance at the network level, through security groups, firewall rules or a private subnet, and test from outside the balancer that the instance does not answer. Also confirm that the admin panel and API are not reachable through an alternate hostname that points at an instance directly.

Limit which forwarded headers are trusted

Strapi builds URLs and client-facing behavior from forwarded headers such as the protocol and host, so a client that can set those headers can influence them. Decide which proxies are allowed to set forwarded headers, configure HAProxy to overwrite rather than pass through values from clients, and confirm that Strapi's proxy trust settings match that single path. Verify the result with a request that sends spoofed headers.

Protect the HAProxy stats and admin interfaces

HAProxy can expose a statistics page and, in some setups, a runtime API. Both show backend names, server states and traffic, and the runtime API can change server states. Decide who needs access, bind these interfaces to a management address or restrict them by source, require authentication, and confirm they are absent from the public listener.

Keep certificates renewed and keys controlled

TLS terminates at HAProxy, so the balancer holds the private key for the public hostname. Decide who issues and renews the certificate, where the combined certificate and key file lives, and who can read it. Check that renewal reloads HAProxy without dropping connections, that the expiry date is monitored, and that backups of the key are protected like other secrets.

Expose the health endpoint only to the balancer

The /_health endpoint is what HAProxy polls to decide whether an instance receives traffic. If it is reachable by the public, it reveals instance state to anyone and can be used to probe the deployment. Route it only on the path HAProxy uses, restrict it to the balancer's source address where your network allows it, and verify that the same path is not exposed through the public hostname.

Log request IDs across HAProxy and Strapi

When a user reports an error, the team needs to match the HAProxy access log line to the Strapi application log line for the same request. Decide which request ID header HAProxy generates or accepts, confirm that Strapi logs it, and check that logs from every instance go to one place with the same retention. Without this, incident review across the two layers takes far longer.

Version and runtime constraints to settle before scaling out

Settle the Strapi version and runtime before you add a second instance. Every upgrade gap, deprecated runtime or database mismatch that exists on one instance is copied to each instance HAProxy adds, and the errors show up as intermittent failures that are harder to trace behind a balancer. Strapi v4 reached end of life on April 30, 2026, and its final release, 4.26.2 of June 9, 2026, will receive no further updates. If your load balancer fronts a v4 project, plan the move to Strapi 5 as a prerequisite for scaling, not as a later task. Use the Strapi v4 to v5 migration introduction and FAQ to scope the codemods, data migration and breaking changes, and back up the database first because downgrading is not supported.

Check the runtime against the supported matrix before you build the HAProxy configuration. Strapi 5 supports PostgreSQL 14 or later, MySQL 8.0 or later, MariaDB 10.3 or later and SQLite 3, and it does not support MongoDB or other NoSQL databases. It also runs only on Active or Maintenance LTS Node.js versions, so confirm that every instance image or VM uses the same supported Node.js release. Record the exact Strapi, Node.js and database versions in your deployment inventory, and confirm them against the Strapi installation requirements at the time you deploy, because the minor releases of Strapi 5 ship roughly weekly.

SQLite is unlikely to fit a multi-instance setup. SQLite stores the database in a single local file, so instances on separate hosts cannot share it safely, and a balancer spreading writes across them invites lock contention and data divergence. Confirm this with your own architecture, including whether all instances can reach one file on shared storage and whether your write volume is acceptable under that model. In most balanced deployments, plan a shared PostgreSQL or MySQL-family database from the start, with the same database credentials and connection limits configured on every instance.

Limits to confirm in your environment

Several of the choices behind a HAProxy setup for Strapi depend on facts outside this page: your HAProxy build, your Strapi version, your database and upload setup, and your license position. Confirm each one before you commit to instance counts or a topology, because a change in any of them can move the design.

HAProxy version and directives

Confirm the HAProxy version your platform packages or supports, and check that the directives you plan to use exist in that release. The health check on /_health, the httpchk option, TLS termination with a certificate bundle, and the forwarded header settings all depend on the build. Record the exact version in your runbook, because a load balancer upgrade is a separate change from a Strapi upgrade and needs its own test pass.

Strapi version and major line

Confirm which Strapi release you run and whether you are on Strapi 5. The health endpoint, proxy trust settings and admin URL behavior are the parts of the stack that a balancer depends on, and they have changed across majors. If you are still on Strapi 4, check the end-of-life date in the migration docs before you design a multi-instance topology that will outlast it.

Strapi migration docs

Database and upload provider concurrency

Each Strapi instance connects to the same database and writes uploads through a provider, so the database must accept the combined connection count and the upload provider must be shared, not local. Confirm that your chosen engine and version are on the supported list, that your connection limits and pool settings add up across instances, and that uploads do not land on one node's disk. Local file storage is the most common reason a balanced setup serves broken media.

Strapi installation requirements

Strapi Cloud versus self-managed balancing

Decide whether you need to run the load balancer yourself at all. Strapi Cloud is a hosted option with its own plan limits and uptime commitments, and it removes the HAProxy, TLS and database work from your team. Compare the plan allowances against your expected API traffic and storage, and weigh that against the control you need over network placement, data location and operations.

Strapi Cloud pricing

License terms for your deployment

Check which parts of Strapi you use and under which license. The Community Edition is under the MIT Expat license, while code under ee directories falls under a separate Strapi license. Features such as SSO, audit logs and review workflows sit on paid plans in the self-hosted model. Ask your legal or procurement team to confirm how these terms apply to a multi-instance production deployment before you rely on any Enterprise feature in the design.

Strapi license file

Load testing to size instances

Measure instance counts against your own workload rather than borrowing a figure from another deployment. Build a test that mirrors your read and write mix, your authenticated and public API calls, and your media requests, then run it against a staging topology with the same HAProxy and database settings as production. Record latency, error rate and database connection use at each step, and repeat the test after every Strapi minor release, since releases ship often.

Questions teams ask before load balancing Strapi

Is a single Strapi instance enough for production?

A single instance can be enough for many internal or low-traffic sites, and the decision depends on availability needs, traffic shape and how often you deploy. One instance means a restart or a failed deploy takes the admin panel and API down. Adding HAProxy only helps when you also run more than one instance, and it adds a component to operate. Before you split traffic, confirm your uptime target, your deployment window and whether your database can handle the connections from several instances. Strapi's own installation requirements cover supported databases and Node.js versions, which apply to every instance you run (Strapi installation requirements).

What drives the cost and effort of a multi-instance Strapi setup?

Four things drive effort: the number of instances, the database and storage design, the test plan and ongoing HAProxy operation. Instance count changes build, configuration and monitoring work. The database must be external and sized for the connection pool of every instance. Uploads must go to shared storage, or to a provider every instance can reach, so files do not depend on one server. Testing covers failover, health check behavior, session handling and schema changes during rolling deploys. Ongoing work includes certificate renewal, HAProxy upgrades and capacity reviews. Ask any partner for a quote that lists each of these as separate line items, with one-time and recurring work marked.

What does the work need from our team?

The work needs access to your infrastructure, the database, certificate management and a named operations owner. Infrastructure access covers the load balancer hosts or cluster, the Strapi hosts and network rules between them. Database access is needed to review connection limits, backups and any schema changes. Certificates require a decision on where TLS ends and who issues and renews them. The operations owner approves changes, receives alerts and decides how incidents are handled after go-live. Confirm these owners and access paths before you request a quote, since delays in any of them usually extend the schedule more than the technical work does.

Can our own team build this without outside help?

Yes, if your team already runs Linux services, reverse proxies and Strapi in production. The core tasks are terminating TLS in HAProxy, defining backends that point to each Strapi instance, configuring health checks against the /_health endpoint and making sure instances share what they must share. The harder part is verifying the result: failover tests, rolling restarts and schema changes across instances. Compare your team's time against the operational load of owning HAProxy after launch. An outside partner can deliver a fixed-scope build with written deliverables, while ongoing support and upgrades are available as retainers.

How long does a HAProxy setup for Strapi take?

Duration depends on scope: the number of instances, how many environments you need, the state of your current database and storage, and how much testing and documentation you require. No duration figure is given here. Ask any provider for a timeline tied to a written scope, and check that it includes failover testing, a rollback plan and handover of configuration. Your own team can estimate more reliably once it has listed the instances, the environments and the shared services that must be in place first.

Do Strapi Cloud or the Growth and Enterprise plans change this decision?

They change who runs the load balancing layer and which features you can use. Strapi Cloud is a hosted service, so load balancing and hosting are handled by Strapi, and its listed plans start at 35 US dollars per month per project for Starter, with 99.9% uptime SLA listed only on Business, according to Strapi's Cloud pricing page (Strapi Cloud pricing). For self-hosting, the Growth plan is listed at 45 US dollars per month including 3 users, and Enterprise is custom priced (Strapi self-hosted pricing). Self-hosted plans do not remove the need for your own HAProxy setup. Confirm current plan terms directly with Strapi before deciding.

How DeployOpen scopes and delivers HAProxy load balancing for Strapi

DeployOpen plans and builds the HAProxy layer in infrastructure you control, from TLS termination to health checks on the Strapi health endpoint. We start with the shared state that every Strapi instance depends on, because that decides whether balancing is safe. The written scope then sets out what gets built, tested and handed over.

How we scope

  • We confirm how many Strapi instances you run, where they sit and which hosts or networks HAProxy can reach.
  • We map what must be shared between instances, including the database, uploads storage, and any sessions or cache layer.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.

How we build

  • We configure HAProxy TLS termination, backend pools and health checks against the Strapi health endpoint on your instances.
  • We align Strapi proxy and server URL settings with the forwarded headers HAProxy sends, then test them end to end.
  • We test failover by taking an instance out of rotation and confirming traffic, admin logins and uploads keep working.

How we hand over

  • You receive the HAProxy configuration, a record of the Strapi settings changed, and the test results from each step.
  • We document the shared-state decisions, including which storage and database endpoints every instance uses.
  • We walk your platform and operations team through adding or removing an instance and rolling out configuration changes.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover.
  • Retainers can cover HAProxy version updates, certificate renewal checks and re-testing after Strapi upgrades.
  • We confirm support scope, response expectations and change handling in writing before the retainer starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.