Search DevFox

Search tools and pages.

Nginx Load Balancer Config Generator

Generate an nginx upstream + load balancer config with round-robin, least_conn, ip_hash, weights, health checks, and keepalive

Loading tool...

What is Nginx Load Balancer Config Generator

Written by Giorgos Kostas. Last reviewed:

Nginx Load Balancer Config Generator emits an `upstream` block listing your backend servers, plus a server block that proxies to it with the load-balancing method that fits your traffic.

It supports the four built-in OSS Nginx methods: round-robin (default), `least_conn`, `ip_hash` (sticky by client IP), and consistent `hash $remote_addr`.

Why use it

  • Drop in dozens of upstream entries from a labelled list instead of hand-editing brace-matched blocks.
  • Switch load-balancing methods from a dropdown — IP hash for sticky sessions, least_conn for long-lived connections, hash for cache-friendly distribution.
  • Add an explicit `/health` endpoint that checks any one upstream from the same listener.
  • Combines cleanly with the Nginx SSL generator for HTTPS-fronted load balancing.

Features

  • Add / remove upstream servers in a labelled list
  • Method selector: round-robin, least_conn, ip_hash, hash
  • Optional `/health` endpoint
  • Combines with proxy headers, gzip, security headers

How to use Nginx Load Balancer Config Generator

  1. Name the upstream. Give it a short identifier (e.g. `backend`).
  2. Add server entries. host:port for each upstream — IPs or DNS names.
  3. Pick a method. Least connections is a strong default for most APIs.
  4. Deploy. Copy + drop into Nginx, `nginx -t`, reload.

Example (before/after)

Form input

upstream name = backend
servers       = app1:3000, app2:3000, app3:3000
method        = least_conn
proxy_pass    = http://backend

Generated config

upstream backend {
  least_conn;
  server app1:3000;
  server app2:3000;
  server app3:3000;
}
server {
  listen 80;
  server_name api.example.com;
  location / {
    proxy_pass http://backend;
    ...
  }
}

Common errors

Sessions reset after every refresh

Round-robin sends each request to a different upstream that doesn't share session state.

Fix: Switch to `ip_hash` or move sessions to a shared store (Redis) and stay on round-robin.

One upstream eats all traffic

DNS round-robin or a stuck `keepalive` pool can pin Nginx to one server.

Fix: Set `keepalive 32;` inside the upstream block and verify each server name resolves correctly.

Active health checks not happening

Built-in OSS Nginx only does passive checks (mark dead on failure).

Fix: Use NGINX Plus or the `nginx_upstream_check_module` patch for active checks; the `/health` endpoint here probes once per request.

FAQ

Which load-balancing method is the right default?

Least connections (`least_conn`) for long-lived requests (websockets, slow APIs). Round robin for short stateless requests. IP hash if you can't move session state out of the upstream. Consistent hash for cache-friendly partitioning.

How does this differ from the reverse-proxy generator?

The reverse-proxy generator targets a single upstream URL. The load balancer generator emits an `upstream { ... }` block with multiple `server` lines and a method, then proxies to the named upstream.

Can I add weights or backup servers?

Append `weight=N` or `backup` to a server line after copying, e.g. `server app1:3000 weight=3;`. The form intentionally keeps inputs simple.

Does Nginx do active health checks?

OSS Nginx only does passive checks (a server is marked unavailable for `fail_timeout` after `max_fails`). Active checks need NGINX Plus or a third-party module.

What's the difference between ip_hash and the hash directive?

`ip_hash` always uses the client IP. `hash $remote_addr consistent` uses a configurable key with consistent hashing — better for cache partitioning when servers are added or removed.

Where do I add SSL termination?

Use the Nginx SSL Config Generator for the front server, then paste the upstream block from this tool. Or extend the output with the `listen 443 ssl;` directives.