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

85 lines
2.1 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 gRPC 代理配置示例
# ============================================================
#
# 功能说明:
# - gRPC 协议代理HTTP/2
# - 流式 RPC 支持
# - 负载均衡
#
# Lolly 对应配置:
# server:
# ssl:
# http2:
# enabled: true
# proxy:
# - path: "/grpc"
# targets:
# - url: "grpc://grpc-server:50051"
# # gRPC 需要 HTTP/2 支持
# ============================================================
upstream grpc_backend {
server grpc1:50051;
server grpc2:50051;
keepalive 32;
}
server {
listen 443 ssl http2;
server_name grpc.example.com;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
# gRPC 代理
location /grpc {
# gRPC 使用 HTTP/2
# Lolly 对应: grpc:// 协议前缀
grpc_pass grpc://grpc_backend;
# gRPC 超时
grpc_read_timeout 60s;
grpc_send_timeout 60s;
grpc_connect_timeout 5s;
# gRPC 缓冲
grpc_buffer_size 4k;
}
# gRPC Web 代理(浏览器访问 gRPC
# 需要 grpc-web 模块或第三方代理
location /grpcweb {
grpc_pass grpc://grpc_backend;
# gRPC Web 特殊处理
grpc_set_header X-Grpc-Web 1;
}
}
# gRPC 代理说明:
#
# 1. gRPC 协议:
# - 基于 HTTP/2
# - 支持 Unary、Server Streaming、Client Streaming、Bidirectional Streaming
# - 使用 Protobuf 序列化
#
# 2. nginx grpc_pass 指令:
# - grpc:// - 明文 gRPCHTTP/2 无 TLS
# - grpcs:// - 加密 gRPCHTTP/2 + TLS
# - 自动处理 HTTP/2 framing
#
# 3. Lolly 支持:
# - HTTP/2 需要启用 SSL
# - gRPC 代理通过 HTTP/2 协议实现
# - 支持流式 RPC
#
# 4. 超时配置:
# - grpc_read_timeout: 等待响应超时
# - grpc_send_timeout: 发送请求超时
# - 流式 RPC 需要较长超时
#
# 5. 负载均衡:
# - gRPC 支持标准 HTTP/2 负载均衡
# - 建议 least_conn 或 round_robin