Load Balancer Generator

Configure highly available TCP/HTTP load balancers with active health checks.

Load Balancer Settings

Core Settings

haproxy.cfg
Valid
1
0
Overall Score

Configuration Health

High availability analysis for the configured load balancer.

Detailed Analysis

Best Practice Analysis

  • Use at least two backend servers for true HA.
  • Enable active health checks (HAProxy).
  • Ensure frontend and backend ports match your firewall rules.

Production Readiness

  • Valid Upstreams
  • Health Checks Active

Overview

The Load Balancer Configuration Generator helps you scale your applications horizontally across multiple backend servers using NGINX or HAProxy.

When a single server can no longer handle the traffic volume, a load balancer acts as a traffic cop, sitting in front of your servers and routing client requests across all servers capable of fulfilling them in a manner that maximizes speed and capacity utilization. This tool ensures no single server gets overworked, automatically handling degraded servers with built-in health checks.

How It Works

1. Define Upstreams: Enter the IP addresses or hostnames of your backend application servers. These form the 'upstream pool'.

2. Choose an Algorithm: Select how traffic is distributed. Round Robin cycles through servers sequentially. Least Connections sends traffic to the server with the fewest active requests. IP Hash ensures a specific user always hits the same backend server (useful for session state).

3. Configure Health Checks: Enable active (HAProxy) or passive (NGINX) health checks. If a backend server fails to respond, the load balancer temporarily removes it from the pool until it recovers.

4. Session Persistence: If your application stores user sessions in memory (instead of a shared database like Redis), you can enable sticky sessions to bind a user's session to a specific server via cookies.

Best Practices

  • Always use **Least Connections** (`least_conn`) instead of Round Robin if your application has long-lived requests or unpredictable response times. This prevents slow requests from piling up on a single server.
  • If your application uses WebSockets, ensure you increase the `proxy_read_timeout`. Load balancers typically drop idle HTTP connections after 60 seconds, which will prematurely disconnect WebSocket users.
  • Configure `max_fails` and `fail_timeout` on your upstream servers to instruct the load balancer exactly when to consider a node 'dead' and how long to wait before retrying it.
  • Offload SSL/TLS termination at the load balancer layer. This significantly reduces the CPU load on your backend application servers.

Common Mistakes

  • Using IP Hashing behind Cloudflare or another CDN. Because all traffic comes from the CDN's IP addresses, IP Hashing will route *all* traffic to a single backend server, entirely defeating the load balancer.
  • Forgetting to share session state (e.g., PHP sessions) between backend servers without enabling Sticky Sessions. Users will randomly get logged out as they are routed to different nodes.
  • Not setting `proxy_set_header X-Forwarded-For`. Without this, every backend server will think every request is coming from the internal IP of the Load Balancer.

Security Recommendations

  • Place your backend application servers on a private network (VPC/LAN) that is completely isolated from the internet. Only the Load Balancer should have a public IP address.
  • Configure a WAF (Web Application Firewall) at the load balancer layer to filter malicious traffic before it ever reaches your application servers.
  • Set strict Connection Limits (`conn_limit`) per IP address at the load balancer to mitigate volumetric DDoS attacks.

Production Tips

  • Enable Keep-Alive between the Load Balancer and the backend servers. This prevents the load balancer from having to negotiate a new TCP handshake for every single request forwarded to the backend.
  • If using HAProxy, use the `httpchk` option to make HAProxy explicitly request a `/health` endpoint on your app. TCP checks only verify the port is open; HTTP checks verify the app is actually alive.
  • Set a backup server (`backup` flag) in your upstream pool that only receives traffic if all primary servers fail. This is perfect for showing a static 'Maintenance Mode' page.

Frequently Asked Questions

Which algorithm should I use?
Round Robin is best for simple, fast requests (like serving static files). Least Connections is best for APIs and applications where request processing time varies. IP Hash is only needed if your app cannot share state between servers.
What is an Active vs Passive Health Check?
Passive (NGINX Free) monitors live user traffic; if a user's request fails, the server is marked down. Active (HAProxy or NGINX Plus) proactively sends health-check probes (e.g., every 5 seconds) regardless of user traffic.
Can a Load Balancer improve database performance?
Yes, but you must use TCP mode (Stream). Both HAProxy and NGINX can load balance raw TCP connections to read-replicas in a PostgreSQL or MySQL cluster.

Related Generators