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

98 lines
2.5 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 HTTP/2 配置示例
# ============================================================
#
# 功能说明:
# - HTTP/2 多路复用
# - 头部压缩HPACK
# - 服务器推送Server Push
# - 流控制配置
#
# Lolly 对应配置:
# server:
# ssl:
# cert: "/path/to/cert.pem"
# key: "/path/to/key.pem"
# http2:
# enabled: true
# max_concurrent_streams: 128
# max_header_list_size: 1048576
# idle_timeout: 120s
# push_enabled: false
# ============================================================
server {
listen 443 ssl http2;
server_name http2.example.com;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
# HTTP/2 配置
# Lolly 对应: ssl.http2 配置块
# 最大并发流(默认 128
http2_max_concurrent_streams 128;
# 最大头部大小(默认 16KB
http2_max_header_field_size 16384;
# 最大请求体大小
http2_max_requests 1000;
# 空闲超时
http2_idle_timeout 120s;
# 服务器推送(默认关闭)
http2_push_preload off; # 从 Link 头自动推送
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
# 手动服务器推送示例
# http2_push /style.css;
# http2_push /script.js;
}
# 启用 Link 头推送
location /preload {
# Link 头自动推送
add_header Link "</style.css>; rel=preload; as=style";
add_header Link "</script.js>; rel=preload; as=script";
http2_push_preload on;
root /var/www/html;
}
}
# HTTP/2 说明:
#
# 1. HTTP/2 优势:
# - 多路复用: 单连接并发多个请求
# - 头部压缩: HPACK 算法,减少头部大小
# - 服务器推送: 预推送资源,减少请求
# - 二进制协议: 解析效率更高
#
# 2. ALPN 协商:
# - 客户端发送 ALPN 扩展: h2, http/1.1
# - 服务端选择 h2 返回
# - 无 ALPN 时 fallback 到 HTTP/1.1
#
# 3. 服务器推送:
# - Link 头: <url>; rel=preload
# - http2_push_preload on: 自动推送
# - http2_push: 手动推送
#
# 4. 流控制:
# - max_concurrent_streams: 并发流限制
# - 避免客户端占用过多资源
#
# 5. H2C明文 HTTP/2:
# - http2 直接在 TCP 上(无 TLS
# - 需要 HTTP/2 prior knowledge 或 Upgrade 头
# - 大多数浏览器不支持 H2C
# - Lolly 对应: ssl.http2.h2c_enabled