Advanced Load Balancing Strategies

Advanced Load Balancing Strategies

Implement sophisticated load balancing with health checks:

# Nginx advanced load balancing
upstream backend_servers {
    # IP hash for session persistence
    ip_hash;
    
    # Servers with weights
    server backend1.internal:8080 weight=3 max_fails=2 fail_timeout=30s;
    server backend2.internal:8080 weight=2 max_fails=2 fail_timeout=30s;
    server backend3.internal:8080 weight=1 max_fails=2 fail_timeout=30s;
    
    # Health check parameters
    check interval=5000 rise=2 fall=3 timeout=4000 type=http;
    check_http_send "GET /health HTTP/1.1\r\nHost: localhost\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;
}

# Active health monitoring
server {
    listen 127.0.0.1:8888;
    
    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
    
    location /upstream_status {
        check_status;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}