Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

load-balancer

БесплатноБез исполняемых скриптовНе проверен

Configures load balancers and reverse proxies with Nginx and HAProxy: upstream pools, least-connections balancing, HTTPS termination, health checks, rate…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Load Balancer

Overview

Covers production setups for two proxies. Nginx is the default choice for HTTPS termination, simple pools and static content. HAProxy is the better fit for active health checks, stick tables, cookie persistence and a stats page. Cloud balancers (AWS ALB/NLB) and Kubernetes ingress controllers are configured with their own APIs and are out of scope here. The configs below pass nginx -t on nginx 1.30 and haproxy -c on HAProxy 3.4.

Instructions

Step 1: Choose the architecture

  • Single service, HTTPS needed: Nginx reverse proxy.
  • Several backends with different routing rules: Nginx upstream groups, or HAProxy ACLs.
  • TCP/UDP traffic (databases, Redis): Nginx stream block, or HAProxy mode tcp.
  • Active health checks, stick tables, a live stats page: HAProxy. Open-source Nginx only has passive checks.
  • Kubernetes: use an ingress controller instead of hand-written configs.

Step 2: Nginx main config

/etc/nginx/nginx.conf:

user nginx;
worker_processes auto;
worker_rlimit_nofile 65535;

events {
    worker_connections 4096;
}

http {
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 65;
    server_tokens off;

    # Log upstream timing next to total request time
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" rt=$request_time urt=$upstream_response_time';
    access_log /var/log/nginx/access.log main;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript image/svg+xml;

    # Rate limiting zones: 10 MB holds roughly 160k client addresses
    limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
    limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
    limit_req_status 429;

    # Upgrade header handling for WebSocket and plain requests
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      '';
    }

    upstream api_backends {
        least_conn;
        keepalive 32;
        server api1.internal:3000 weight=3 max_fails=3 fail_timeout=30s;
        server api2.internal:3000 weight=3 max_fails=3 fail_timeout=30s;
        server api3.internal:3000 backup;
    }

    upstream ws_backends {
        ip_hash;
        server ws1.internal:8080;
        server ws2.internal:8080;
    }

    include /etc/nginx/conf.d/*.conf;
}

Step 3: Nginx HTTPS server

/etc/nginx/conf.d/app.conf. Since nginx 1.25.1 listen 443 ssl http2; is deprecated and prints a warning; use the separate http2 on; directive.

server {
    listen 80;
    server_name api.shopwise.io;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    http2 on;
    server_name api.shopwise.io;

    ssl_certificate     /etc/letsencrypt/live/api.shopwise.io/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.shopwise.io/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;

    # Settings shared by every proxied location (a location with its own proxy_set_header must repeat them)
    proxy_http_version 1.1;
    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        "";   # keeps upstream keepalive working
    proxy_connect_timeout 5s;
    proxy_read_timeout 30s;

    location / {
        limit_req zone=api burst=20 nodelay;
        proxy_pass http://api_backends;
        # Retry another server on errors, but never replay POST/PATCH (non-idempotent)
        proxy_next_upstream error timeout http_502 http_503;
        proxy_next_upstream_tries 2;
    }

    location /api/auth/login {
        limit_req zone=login burst=3 nodelay;
        proxy_pass http://api_backends;
    }

    location /ws/ {
        proxy_pass http://ws_backends;
        # proxy_set_header here replaces the server-level set, so repeat the shared ones
        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 Upgrade           $http_upgrade;
        proxy_set_header Connection        $connection_upgrade;
        proxy_read_timeout 3600s;
    }

    location ~ /\.(git|env|htaccess) {
        return 404;
    }
}

Always run nginx -t before nginx -s reload. Nginx resolves upstream hostnames only at startup, so a name that does not resolve stops the test.

Step 4: HAProxy

/etc/haproxy/haproxy.cfg. The PEM file must contain the certificate chain followed by the private key. Export the stats password as HAPROXY_STATS_PASSWORD in the serv

Полный SKILL.md на GitHub

Установить load-balancer в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл load-balancer?

Configures load balancers and reverse proxies with Nginx and HAProxy: upstream pools, least-connections balancing, HTTPS termination, health checks, rate limiting, sticky sessions and WebSocket proxying. Use when someone asks to "set up load balancing", "configure an Nginx reverse proxy", "set up HAProxy", "add SSL termination", "configure health checks", "proxy WebSocket connections", "rate limit traffic", or "set up failover".

Как установить скилл load-balancer?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл load-balancer запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить load-balancer с