Backend Development 4 min read

Comprehensive Guide to Nginx Load Balancing and Algorithms

This article provides an in‑depth overview of Nginx as a high‑performance load‑balancing middleware, explaining its core concepts, configuration syntax, and the four main balancing algorithms—Round Robin, Weighted Round Robin, IP Hash, and Least Connections—along with practical code examples.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Comprehensive Guide to Nginx Load Balancing and Algorithms

Nginx is a high‑performance HTTP and reverse‑proxy server widely used for load balancing, caching, and serving static resources.

It distributes traffic among backend servers to improve availability and reliability.

Typical configuration uses an upstream block that lists the backend IPs, e.g.:

upstream backend {
    server 192.168.1.101;
    server 192.168.1.102;
    server 192.168.1.103 backup;
}

The article explains several load‑balancing algorithms:

Round Robin – default, sends requests sequentially to each server.

Weighted Round Robin – adds a weight parameter so servers with higher weight receive more requests.

IP Hash – hashes the client IP to consistently route the same client to the same server, useful for session persistence.

Least Connections – directs traffic to the server with the fewest active connections, ideal for long‑lived connections.

Example configuration for weighted round robin:

http {
    upstream mikechen {
        server server1.mikechen.cc weight=3; # receives more requests
        server server2.mikechen.cc weight=1;
        server server3.mikechen.cc weight=2;
    }
    server {
        listen 80;
        location / { proxy_pass http://mikechen; }
    }
}

Understanding these algorithms helps design scalable and resilient architectures.

Backend Developmentload balancingnginxRound Robinip_hashweighted round robinleast connections
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.