Back to Docs
Documentation

Nginx Load Balancing Explained

Learn how to configure Nginx load balancing with upstream blocks, methods, and health checks.

What is Load Balancing?

Load balancing distributes incoming requests across multiple backend servers to improve performance, reliability, and scalability.

Load Balancing Methods

Round Robin (Default)

Distributes requests evenly across all servers:
upstream backend {
    server 10.0.0.1:8080;
    server 10.0.0.2:8080;
}

Least Connections

Sends requests to the server with fewest active connections:
upstream backend {
    least_conn;
    server 10.0.0.1:8080;
    server 10.0.0.2:8080;
}

IP Hash

Ensures requests from the same IP always go to the same server (session persistence):
upstream backend {
    ip_hash;
    server 10.0.0.1:8080;
    server 10.0.0.2:8080;
}

Server Weights

Assign different weights to servers:

upstream backend {
    server 10.0.0.1:8080 weight=3;
    server 10.0.0.2:8080 weight=1;
}

Health Checks

Configure passive health checks:

upstream backend {
    server 10.0.0.1:8080 max_fails=3 fail_timeout=30s;
    server 10.0.0.2:8080 max_fails=3 fail_timeout=30s;
}

Generate your load balancing config with our visual generator!

Ready to build your config?

Use Configen to generate or audit your server configuration — no coding required.