When one application server is no longer enough, or you want the site to survive a server failure, the next step is several application servers behind a load balancer. Nginx can do this with a few lines of configuration. The configuration is the easy part, though: the real work is making the application stateless so any server can handle any request.
First: Do You Need to Scale Out?
Adding servers adds complexity: more machines to patch, deploys that must reach all of them, and a load balancer that is itself a single point of failure unless you double it. Moving to a larger VPS (vertical scaling) is often simpler and is enough for a surprising amount of traffic. Scale out when:
- one server is near its limit even on a large plan, or the workload is CPU-bound and parallelises well;
- you need the site to stay up while one server is being patched or fails;
- you want to deploy without downtime by draining one server at a time.
Often the database is the real bottleneck. Measure first (see our monitoring guide); more app servers do not help if every request waits on the same database.
Architecture
┌─▶ app1 (10.0.0.11:8000)
Internet ─HTTPS─▶ LB ┼─▶ app2 (10.0.0.12:8000) ──▶ database (10.0.0.20)
(Nginx :443) └─▶ app3 (10.0.0.13:8000) ──▶ Redis (sessions, cache)
Use private networking between the servers if your provider offers it; otherwise restrict each app server's port to the load balancer's IP with a firewall rule and encrypt the traffic (TLS to the backends, or a WireGuard tunnel) because it crosses the public network.
Step 1: The Upstream Block
# /etc/nginx/conf.d/app-upstream.conf on the load balancer
upstream app_backend {
least_conn;
server 10.0.0.11:8000 max_fails=3 fail_timeout=15s;
server 10.0.0.12:8000 max_fails=3 fail_timeout=15s;
server 10.0.0.13:8000 max_fails=3 fail_timeout=15s;
keepalive 32;
}
| Method | How it chooses | Good for |
|---|---|---|
| (default) round robin | Each server in turn, optionally weighted | Similar servers, short similar requests |
least_conn | Server with the fewest active connections | Requests of varying length (the usual best default) |
ip_hash | Same client IP to the same server | Legacy apps that keep sessions in local memory |
hash $key consistent | Same key to the same server | Cache locality, for example by URL |
Add weight=2 to give a larger server more traffic, backup for a server used only when others fail, and down to take one out of rotation for maintenance.
Step 2: The Load Balancer Server Block
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://app_backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_next_upstream error timeout http_502 http_503;
proxy_next_upstream_tries 2;
proxy_connect_timeout 3s;
}
}
Then add HTTPS on the load balancer only (sudo certbot --nginx -d example.com). The app servers receive plain HTTP from the load balancer and must trust its X-Forwarded-* headers, but only from the load balancer's IP.
Step 3: Health Checks
Open-source Nginx uses passive health checks: if a server fails max_fails times within fail_timeout, Nginx stops sending it traffic for fail_timeout, then tries again. proxy_next_upstream retries a failed request on another server.
Two cautions:
- Only retry requests that are safe to repeat. By default Nginx does not retry non-idempotent requests (such as POST) after they have been sent to an upstream, which protects you from duplicate orders; keep it that way.
- Active health checks (probing
/healthon a schedule) are a feature of NGINX Plus. With open-source Nginx, combine passive checks with your monitoring system, or use HAProxy, which has active checks built in.
Step 4: Make the Application Stateless
This is what actually makes load balancing work:
| State | Problem with several servers | Fix |
|---|---|---|
| Sessions in local files or memory | Users are logged out when they hit another server | Store sessions in Redis or the database (or use ip_hash as a stopgap) |
| Uploaded files on local disk | Files exist on only one server | Object storage (S3-compatible), or a shared file server |
| Local caches | Each server has different cached data | Shared Redis cache (see our Redis guide) |
| Cron jobs on every server | Jobs run three times | Run scheduled jobs on one designated server, or use a lock |
| Different code versions | Inconsistent behaviour mid-deploy | Deploy to all servers with one script; drain servers one at a time |
Step 5: Rolling Deploys
A load balancer makes zero-downtime deploys straightforward:
- Mark one server
downin the upstream and reload Nginx (in-flight requests finish). - Deploy to it and check its health endpoint directly.
- Put it back and repeat for the next server.
Database migrations must stay backward compatible while old and new versions run side by side; our zero-downtime deployment guide covers the expand/contract pattern.
The Load Balancer Is a Single Point of Failure
One load balancer means one server whose failure takes the site down. Options to remove it, in increasing complexity:
- Accept it: a small, rarely changed Nginx server is very reliable, and you can rebuild it from configuration management in minutes.
- Use DNS with several A records or a DNS failover service in front of two load balancers.
- Use a floating IP with keepalived (VRRP) between two load balancers, if your provider supports moving an IP between servers.
SkyRainCloud Plans for This Workload
A load balancer itself needs little: a 2 vCore / 8 GB server proxies a lot of traffic. Size the application servers for the per-server load, and give the database its own larger plan, since it is usually the first shared bottleneck.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Intel Xeon Platinum 8269CY VPS
KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check stock |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| Users randomly logged out | Sessions stored locally; move them to Redis or the database |
| One server gets most traffic | Long-lived connections with round robin; switch to least_conn |
| All servers show the load balancer's IP as client | App not reading X-Forwarded-For from the trusted LB IP |
| 502 during deploys | Servers restarted while still in rotation; drain them first |
| Uploaded images missing intermittently | Files saved on a single server's disk; use shared storage |
Frequently Asked Questions
Can Nginx be used as a load balancer?
upstream module distributes requests across servers with round robin, least connections or hashing, and passive health checks skip failed servers.Round robin or least_conn?
least_conn is usually the better default because request durations vary. Round robin works well when servers and requests are uniform.Does open-source Nginx support active health checks?
max_fails, fail_timeout); HAProxy offers active checks for free.Where should HTTPS be terminated?
How do I handle sessions with a load balancer?
ip_hash) work but distribute load unevenly and break when a server fails.When should I scale out instead of up?
Is the load balancer a single point of failure?
How many app servers do I need?
Do the app servers need public IPs?
Which SkyRainCloud plans suit a load-balanced setup?
Related Guides
- How to Configure Nginx as a Reverse Proxy for Multiple Applications
- How to Achieve Zero-Downtime Deployments on a Single VPS
- How to Deploy Redis on a VPS for Application Caching
- How to Set Up Monitoring and Logging for Applications on a VPS
- How to Set Up HTTPS on a VPS with Let's Encrypt and Certbot
- Offshore VPS Hosting Pricing India — KVM VPS India
- How to Reduce Lag on Your Minecraft Server — Ultimate Guide
- SSD VPS Hosting India — NVMe SSD & Root Access