SuperAPI AI Directory

networking-gateway

Deployment & operations

View repository

Updated 10-16 09:59

About this skill

Networking & Gateway

Reference sources: Nginx official documentation, Traefik documentation, AWS ALB/NLB documentation, Cloudflare documentation, Let's Encrypt / cert-manager documentation.

Applicable scenarios

  • Reverse proxy and load balancing configuration
  • API Gateway design (routing / rate limiting / authentication)
  • SSL/TLS certificate management (automatic renewal)
  • DNS record management and switching
  • CDN configuration and caching strategy
  • Multi-service traffic routing (path / domain)
  • WebSocket / gRPC proxy
  • DDoS protection and WAF

Core principles

1. TLS Everywhere
   所有外部流量 HTTPS
   内部服务间 mTLS(Service Mesh)
   HSTS 强制

2. 最小暴露
   只暴露必要端口
   内部服务不直接对外
   安全组 / NetworkPolicy 限制

3. 高可用
   负载均衡多实例
   健康检查剔除故障节点
   DNS 多记录 / Failover

4. 缓存分层
   CDN → 反向代理 → 应用
   静态资源长缓存 + 版本化
   API 按需缓存

5. 限流保护
   全局限流 + 按 IP / 用户
   突发容忍 + 平滑限流
   429 返回 Retry-After

6. 可观测
   访问日志结构化
   延迟 / 错误率 / 流量指标
   实时流量可视化

7. 零停机变更
   配置热加载
   DNS 切换 TTL 提前降低
   蓝绿 / 金丝雀流量切分

Workflow

1. 网络架构设计
   - 外部流量入口(CDN → LB → Gateway)
   - 内部服务通信(Service Mesh / 直连)
   - 网络分段(公有 / 私有子网)

2. DNS 配置
   - 域名注册与托管
   - A / CNAME / ALIAS 记录
   - TTL 策略(正常 300s,切换前降至 60s)

3. SSL/TLS 证书
   - cert-manager 自动签发(Let's Encrypt)
   - 通配符证书(*.example.com)
   - 证书到期监控

4. 反向代理 / 网关
   - 路由规则(路径 / 域名 / Header)
   - 上游健康检查
   - 超时与重试配置
   - WebSocket / gRPC 支持

5. 负载均衡
   - 算法选择(Round Robin / Least Conn / IP Hash)
   - 会话保持(如需)
   - 跨 AZ 分布

6. 安全加固
   - WAF 规则(OWASP Top 10)
   - Rate Limiting
   - IP 白名单 / 黑名单
   - Bot 检测

7. CDN 配置
   - 静态资源缓存规则
   - 动态内容 bypass
   - 缓存失效策略(purge)

8. 监控与告警
   - 4xx / 5xx 错误率
   - P50 / P95 / P99 延迟
   - 带宽与连接数

Technology selection

Solution Applicable scenarios Advantages Disadvantages
Nginx General-purpose reverse proxy High performance, mature ecosystem Complex configuration
Traefik K8s / Docker native Automatic discovery, hot reload Slightly inferior under high concurrency
AWS ALB AWS cloud-native Managed, maintenance-free Vendor lock-in
Cloudflare CDN + WAF + DNS Global nodes, DDoS protection Depends on third party
Kong API Gateway Rich plugins Complex operations
Envoy Service Mesh Strong L7 capabilities High learning curve

Nginx core configuration patterns

# 反向代理 + 负载均衡
upstream backend {
    least_conn;
    server app1:3000 weight=3;
    server app2:3000 weight=1;
    keepalive 32;
}

server {
    listen 443 ssl http2;
    server_name api.example.com;

    ssl_certificate     /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;

    # 安全头
    add_header Strict-Transport-Security "max-age=31536000" always;
    add_header X-Content-Type-Options nosniff;

    # 限流
    limit_req zone=api burst=20 nodelay;

    location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_connect_timeout 5s;
        proxy_read_timeout 30s;
    }
}

Quality self-check

□ 所有外部流量走 HTTPS
□ HSTS 已启用
□ SSL 证书自动续期
□ 健康检查已配置(剔除故障节点)
□ Rate Limiting 已配置
□ 安全头已添加(HSTS / X-Content-Type / X-Frame)
□ 访问日志结构化输出
□ 超时合理设置(connect / read / write)
□ CDN 缓存规则正确(静态长缓存、API 不缓存)
□ DNS TTL 合理
□ WebSocket / gRPC 代理正确(如需)
□ 负载均衡算法合适
□ 跨 AZ / 多节点部署
□ WAF 规则已启用

Common pitfalls

  1. Not configuring HSTS——man-in-the-middle downgrade attack
  2. Certificate expiration——entire site unavailable
  3. Timeouts too long——slow requests exhaust the connection pool
  4. No rate limiting——a single user can overwhelm the service
  5. CDN caching API responses——data inconsistency
  6. DNS TTL too long——switching takes effect slowly
  7. Not forwarding the real IP——logs are all LB addresses
  8. WebSocket without upgrade——connection failure
  9. HTTP → HTTPS without redirect——mixed content
  10. Load balancing without health checks——traffic hits failed nodes
  11. Wildcard certificate not renewed——all subdomains go down
  12. Nginx reload without testing——configuration errors cause downtime

Supporting templates

  • templates/nginx-config-template.md — Complete configuration template for Nginx reverse proxy + SSL + rate limiting

Collaboration with other skills

上游:
  infrastructure-as-code → VPC / 子网 / LB 基础设施
  kubernetes-orchestration → Ingress Controller

下游:
  release-strategy → 流量切分(金丝雀 / 蓝绿)
  monitoring-alerting → 网关指标采集
  secrets-config → SSL 证书 / API Key 管理
  ci-cd-pipeline → DNS 切换自动化