xfy 6543422281 docs: 添加 Nginx 配置和 Lua 脚本示例文档
- config: 反向代理、缓存、负载均衡、安全、SSL 等配置模板
- lua: API 网关、认证、动态路由、限流、WebSocket 等脚本示例

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00

66 lines
1.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================================
# Nginx 负载均衡 - 加权轮询配置示例
# ============================================================
#
# 功能说明:
# - 按权重分配请求比例
# - 适用于服务器性能差异场景
# - 权重越大,分配请求越多
#
# Lolly 对应配置:
# server:
# proxy:
# - path: "/api"
# targets:
# - url: "http://backend1:8080"
# weight: 5
# - url: "http://backend2:8080"
# weight: 3
# - url: "http://backend3:8080"
# weight: 2
# load_balance: "weighted_round_robin"
# ============================================================
upstream backend {
# 加权轮询
# Lolly 对应: load_balance: "weighted_round_robin",每个 target 设置 weight
# 权重比例 5:3:2 = backend1 处理 50% 请求
server backend1:8080 weight=5;
server backend2:8080 weight=3;
server backend3:8080 weight=2;
# 备用服务器(权重为 0仅在主服务器故障时启用
server backend4:8080 backup;
keepalive 32;
}
server {
listen 80;
server_name weighted.example.com;
location /api {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
# 权重计算示例:
#
# 总权重 = 5 + 3 + 2 = 10
#
# 每 10 个请求的分配:
# backend1: 5 个请求 (50%)
# backend2: 3 个请求 (30%)
# backend3: 2 个请求 (20%)
#
# 实际分配序列: 1,1,1,1,1,2,2,2,3,3, 1,1,1,1,1,2,2,2,3,3...
#
# 使用场景:
# 1. 高性能服务器分配更多请求
# 2. 新服务器逐步上线(先设置低权重)
# 3. 混合部署(物理机权重高,虚拟机权重低)