Load balancers
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
The Load balancers page (/load-balancers, in the Advanced area) fronts a
single public endpoint and spreads incoming requests across a pool of backend
servers — if one backend goes down, traffic shifts to the healthy ones with no
downtime. Because the pool draws from several VPSes, a load balancer belongs to
your whole account rather than to any one server. Creating and applying a load
balancer needs the Pro plan or higher (lower plans get 403 tier_required);
listing and reading are open on every plan.
Create a load balancer, step by step
Section titled “Create a load balancer, step by step”- Click New load balancer to open the create drawer.
- Enter a Name (lowercase letters, digits and hyphens) and pick the Listening port — 443 or 80. Choosing 443 turns on TLS automatically.
- Choose the LB node — the managed server from your fleet that runs the engine and serves the public endpoint. It must be a full MZPanel-managed (agent) server.
- Pick the Engine:
- Nginx reuses the Nginx already on the node. Passive health checks; no per-backend traffic stats.
- HAProxy is a purpose-built LB with active health checks and real per-backend traffic stats. It’s installed on the node on first use.
- Pick the Balancing algorithm — Round-robin (rotate evenly), Least connections (fewest open connections wins), or IP hash (pin each client IP to the same backend for sticky sessions without cookies).
- Build the Backend pool: check the servers you want in the pool, and set each
one’s Port (default
8080) and Weight. - Set the Health check — probe Path (
/healthz), Interval, and the Healthy / Unhealthy thresholds that move a backend in and out of rotation. - Leave TLS termination on to terminate HTTPS at the load balancer (backends then receive plain HTTP), or turn it off.
- Optionally enter Hostnames — the names the load balancer serves, such as
app.example.com, www.example.com(up to 10). Point each name’s A record at the LB node. With TLS on, a Let’s Encrypt certificate for those names is issued automatically (see Hostnames and certificates). Without hostnames the load balancer answers on the node’s own address. - Click Create load balancer. MZPanel writes the definition and pushes it to the LB node; the card shows Pending apply until the node reports back.
What else you can do
Section titled “What else you can do”The page lists each load balancer as a card, with a stats strip on top showing the total count, Healthy backends (healthy / total) and Applied (applied / total).
- Expand a card to see the backend pool: each backend’s health dot, address, weight, and when it was last checked.
- Add backend — attach another fleet server to the pool from the inline picker.
- Drain backend — take a backend out of rotation for maintenance without removing it; it keeps existing connections but receives no new traffic.
- Remove backend — detach a server from the pool.
- Edit — change the name, algorithm, listening port, TLS, and health-check path and interval. The engine and LB node are fixed once created.
- Delete — tear the load balancer down. The public endpoint stops serving immediately; the backend servers themselves are untouched.
Hostnames and certificates
Section titled “Hostnames and certificates”A load balancer with hostnames serves exactly those names on the node, next to the node’s own sites: with the Nginx engine it shares port 443 with them (each site and each load balancer is matched by name). The node also answers port 80 for the hostnames: the Let’s Encrypt check, and a redirect to HTTPS for everything else.
About a minute after the config is applied, MZPanel requests one certificate for all the hostnames:
- Over DNS (DNS-01) when every hostname is in a Cloudflare zone you connected
under Connect → DNS. This works even when the record is proxied (orange cloud)
or port 80 is closed. The private key never leaves the node; MZPanel sets the
_acme-challengerecords and removes them afterwards. - Over HTTP (HTTP-01) otherwise, for the hostnames whose A record already points at the node. The rest keep a self-signed certificate and show Waiting for DNS; MZPanel retries them every 30 minutes, or right away when you click Apply.
Expand the card to see each hostname’s state: Valid (with the renewal date), Queued / Issuing, Waiting for DNS, Failed (with Let’s Encrypt’s reason) or Agent update needed (the node’s agent is older than this feature; update it). The TLS pill on the card turns amber while any hostname is not valid. Certificates renew on their own before they expire.
Each hostname can belong to only one load balancer on a node, and not to a site or app on that node.
How it works
Section titled “How it works”The control plane (Postgres) is the source of truth for each load balancer’s definition — a deliberate exception to MZPanel’s “the box owns its state” rule, because an LB spans the fleet and no single VPS owns it (the same model as uptime monitors). The data-plane runs on the one LB node server you chose.
- Every mutation (create, edit, add/remove/drain a backend, delete) is org-scoped
through the
/v1/load-balancersAPI, then re-applied to the node. - On apply, MZPanel builds a self-contained spec and dispatches an
lb.applyjob to the node’s agent, which runsmz lb applynatively — it renders the Nginx upstream or HAProxy config, validates it, and reloads. The card’s state moves Pending apply → Active, or Degraded with the error if the render/reload fails. Delete dispatches anlb.removejob first, then removes the row. - Backend health comes from the HAProxy stats socket (HAProxy engine) or the uptime prober (Nginx engine) — both land in each backend’s health, which the dots and the healthy-count reflect. A card reads Degraded if it has no backends or any unhealthy backend.
- If the LB node is offline, the job is queued and the load balancer stays Pending apply until the node reconnects, at which point the queued apply runs.
Automate it
Section titled “Automate it”Load balancers are a control-plane resource, so you drive them through the API rather
than an on-box mz command (the node-side mz lb apply / mz lb remove commands are
dispatched for you and take a machine-built spec). REST and MCP are on every plan:
| Task | MCP tool | REST | Notes |
|---|---|---|---|
| List with backends and health | load_balancers_list | GET /v1/load-balancers | |
| Create | load_balancers_create (name, lbNodeServerId, engine: nginx or haproxy; optional listenPort, algorithm, tls, hostnames, hcPath, backends) | POST /v1/load-balancers | Pro, level full |
| Change settings | load_balancers_update | PATCH /v1/load-balancers/{id} | hostnames replaces the list; [] clears it |
| Check certificates | load_balancers_list | GET /v1/load-balancers | certs[] per hostname: status, method, expires_at, message |
| Add / change / remove a backend | load_balancers_backend_add, _backend_update, _backend_delete | /v1/load-balancers/{id}/backends[/{bid}] | Add takes ip, port, optional serverId, label, weight; update changes only weight and draining |
| Push the config to the node | load_balancers_apply | POST /v1/load-balancers/{id}/apply | Pro |
| Delete | load_balancers_delete | DELETE /v1/load-balancers/{id} | Opt-in scope data:delete |
Typical sequence: load_balancers_create, then load_balancers_backend_add once per
backend server, then load_balancers_apply, then load_balancers_list to check
health. These operations span servers, so a token limited to a server allowlist is
refused. The node-side commands are catalogued in the
command reference.
Gotchas & troubleshooting
Section titled “Gotchas & troubleshooting”-
HAProxy and hostnames on 80/443 don’t mix. Nginx owns ports 80 and 443 on the node, so a HAProxy load balancer with hostnames must listen on its own port (for example
8443, set through the API); otherwise the API answers400 port_conflict. Use the Nginx engine to serve hostnames on 443. TLS on port 80 with hostnames is refused for the same reason (80 carries the Let’s Encrypt check). -
409 hostname_taken— another load balancer on the same node already serves that hostname. A hostname that is a site or app on the node makes the apply fail with that reason. -
Waiting for DNS that never clears: check the name’s A record points at the LB node (not at Cloudflare’s proxy, unless the zone is connected under Connect → DNS), and that port 80 is reachable.
-
The LB node must be a managed (agent) server. An agentless / Lite box can’t run the engine, so it can’t be picked as the node — the API rejects it.
-
Engine and LB node are locked after creation. Editing changes routing, TLS and health checks only; to move the endpoint to a different server or switch Nginx ↔ HAProxy, delete and recreate.
-
“Pending apply” that never clears usually means the node is offline. The apply job is queued and runs when the node reconnects; check the node’s connection first.
-
Nginx has no per-backend traffic stats. With the Nginx engine, health is passive and per-backend request rates aren’t measured (shown as ”—”, never faked). Choose HAProxy if you need active checks and real per-backend traffic numbers.
-
Draining ≠ removing. A drained backend always reads draining regardless of its probe and takes no new traffic, but stays attached — undrain it to return it to rotation.
-
Deleting frees the endpoint immediately but leaves the backend servers running; only the load balancer in front of them is removed.
Related
Section titled “Related”- Private network — a WireGuard mesh so the LB node reaches its backends privately.
- Uptime monitoring — the prober that also feeds Nginx-engine backend health.
- Your servers — the fleet the LB node and backends come from.