Nginx Load Balancer Config Builder

Configure Nginx as a load balancer across multiple backend servers

Build an Nginx upstream block with multiple backend servers, weights, max_fails, fail_timeout, backup and down flags, keepalive connections, and a proxy_pass server block with forwarding headers. Runs in your browser.

What is the difference between round robin, least_conn, and ip_hash?

Round robin sends each request to the next server in turn. least_conn picks the server with the fewest active connections, which suits long-lived requests. ip_hash routes a given client IP to the same backend, giving basic sticky sessions.

An Nginx load balancer config builder that turns a list of backend servers into a valid upstream block plus a server block that proxies to it. Choose a balancing strategy, tune passive health checks per server, and copy a config that includes the standard forwarding headers so your apps see the real client IP and scheme.

How it works

Nginx load-balances by defining an upstream group of server directives and pointing a proxy_pass at it by name. The builder emits each backend as server host:port weight=… max_fails=… fail_timeout=…, optionally tagged backup or down. The balancing method line (least_conn; or ip_hash;) is placed first inside the block when you pick a non-default strategy.

The server block listens on your chosen port and proxies every request to the upstream over HTTP/1.1 with an empty Connection header — required for keepalive connection reuse. It sets Host, X-Real-IP, X-Forwarded-For, and X-Forwarded-Proto so the backend can reconstruct the original request, and uses proxy_next_upstream to retry the next server on errors or 502/503 responses.

Tips and notes

  • Use weights to send proportionally more traffic to larger machines, for example weight=5 versus weight=1 for a smaller node — this is ignored under ip_hash.
  • Passive health checking via max_fails/fail_timeout is built in, but it only reacts to real traffic. For active probing you need Nginx Plus or an external health checker.
  • Always run nginx -t before reloading. A typo in an upstream server line fails the test and a reload will refuse to apply a broken config.
  • Set a backup server for graceful failover capacity that stays idle until every primary is down, rather than sharing live load.