NGINX Open Source performs passive health checks by default (it detects failures from error responses/timeouts). Active health checks that periodically probe backends are available in NGINX Plus.

Load-balancing algorithms supported by NGINX
NGINX supports several algorithms. Choosing the right one depends on your application workload, server capacity, and session state requirements.- Round Robin (default)
- Weighted Round Robin
- IP hash (sticky sessions)
- Least connections (
least_conn) - Least time (
least_time, available in NGINX Plus)
Round Robin
Round Robin distributes requests in a circular fashion: request 1 → server A, request 2 → server B, request 3 → server C, then back to A. It is the default algorithm and works well when backend servers have similar capacity and identical content.
upstream block (typically inside http { ... } or an included file) and reference that name with proxy_pass to forward requests:
backend name is arbitrary — it is only a handle for the pool. An upstream can include many servers, but 3–10 servers is often more maintainable.
Weighted Round Robin
Weighted Round Robin allows assigning aweight to each server to control the relative share of requests. If server A has weight=4, B weight=2, and C weight=1, A receives four times as many requests as C.

Sticky sessions (ip_hash)
Some apps store session state locally (for example, shopping carts). To ensure a client is routed to the same backend across requests, enable ip_hash, which hashes the client IP to select a backend and provides sticky sessions.

ip_hash ties clients to backends by IP, which may be problematic behind NATs or shared proxies. For more flexible session affinity, consider application-level session stores (Redis, database) or cookies.
Least connections
Theleast_conn algorithm sends a new request to the backend with the fewest active connections. It’s effective when request durations vary, because it avoids overloading servers currently handling long-running connections.

Least time (NGINX Plus)
Theleast_time algorithm selects the backend with the lowest recent response time. Options like last_byte or header control whether NGINX measures time until the last response byte or until the first byte, respectively. This method is available in NGINX Plus.
The
least_time balancing method (and active health checks) are available in NGINX Plus — the commercial edition.Quick comparison: which algorithm to choose
Testing and next steps
To validate any load-balancing configuration, run controlled load tests and monitor backend metrics (CPU, memory, connection counts, response times). Popular tools:ab(ApacheBench) — simple HTTP load testingwrk— multi-threaded HTTP benchmarking for higher concurrencysiege,hey— other lightweight tools
wrk command to generate load:
- NGINX documentation: https://nginx.org/en/docs/
- NGINX Plus features: https://www.nginx.com/products/nginx/
wrk— https://github.com/wg/wrk