$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
NetworkingintermediateNew

Nginx Load Balancing

Share

Configure Nginx load balancing with health checks

Works with OpenClaude

You are a system administrator or DevOps engineer. The user wants to configure Nginx as a load balancer with active health checks across multiple backend servers.

What to check first

  • Run nginx -v to confirm Nginx is installed (version 1.9.0+ required for active health checks)
  • Verify backend servers are accessible: curl http://backend1:8080/health && curl http://backend2:8080/health
  • Check current Nginx configuration location with nginx -T and locate the main config file (usually /etc/nginx/nginx.conf)

Steps

  1. Open /etc/nginx/nginx.conf or create a new upstream config file in /etc/nginx/conf.d/upstream.conf
  2. Define an upstream block with multiple backend servers and assign weights to distribute traffic proportionally
  3. Add the health_uri parameter to each upstream server to specify which endpoint Nginx will check
  4. Configure health check intervals with health_interval (milliseconds) and health_timeout (how long to wait for response)
  5. Set health_type to http and specify health_http_version as HTTP/1.1 for proper health check requests
  6. In your server block, reference the upstream with proxy_pass http://upstream_name; to route traffic
  7. Add proxy_set_header Host $host; and proxy_set_header X-Real-IP $remote_addr; to preserve client info
  8. Test the configuration with nginx -t and reload with systemctl reload nginx or nginx -s reload

Code

# /etc/nginx/conf.d/load_balancer.conf

upstream backend_servers {
    least_conn;
    
    server backend1.local:8080 weight=5 max_fails=3 fail_timeout=30s;
    server backend2.local:8080 weight=3 max_fails=3 fail_timeout=30s;
    server backend3.local:8080 weight=2 max_fails=3 fail_timeout=30s;
    
    # Active health checks (Nginx Plus feature, requires commercial license)
    # For open-source Nginx, use passive health checks with max_fails/fail_timeout
    
    keepalive 32;
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://backend_servers;
        proxy_http_version 1.1;
        
        # Preserve original request headers
        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_set_header Connection "";
        
        # Timeouts
        proxy_connect_timeout 5s;
        proxy_send_

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryNetworking
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
nginxload-balancinghealth-checks

Install command:

curl -o ~/.claude/skills/nginx-load-balance.md https://clskills.in/skills/networking/nginx-load-balance.md

Related Networking Skills

Other Claude Code skills in the same category — free to download.

Want a Networking skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.