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

33 lines
780 B
Markdown

# Logging & Monitoring
Lua 示例项目,演示如何在 Nginx 中使用 Lua 进行结构化日志输出和请求指标收集。
## 文件说明
| 文件 | 说明 |
|------|------|
| `nginx.conf` | Nginx 配置示例,集成 Lua 日志和指标模块 |
| `log_formatter.lua` | 自定义 JSON 结构化日志格式化 |
| `metrics.lua` | 请求耗时统计与指标收集 |
## 使用方法
1.`nginx.conf` 中的路径调整为实际部署路径
2.`nginx.conf``http` 块中引入 Lua 模块
3. 重启 Nginx 即可生效
## 日志输出格式
```json
{
"time": "2026-04-10T12:00:00Z",
"remote_addr": "127.0.0.1",
"method": "GET",
"uri": "/api/users",
"status": 200,
"request_time": 0.035,
"upstream_time": 0.028,
"body_bytes_sent": 1024
}
```