lolly/config.example.yaml
xfy ec916d882d feat(proxy,middleware,config): 集成配置与代码差异修复
- 集成一致性哈希负载均衡到 proxy.go,支持 hash_key 和 virtual_nodes 配置
- 集成滑动窗口限流算法到 ratelimit.go,支持 algorithm 选择
- 应用 Transport 连接池配置到 createHostClient
- 集成 HSTS 配置到安全头部中间件
- 补充 config.example.yaml 缺失配置(http3、gzip_static、sliding_window)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:08:45 +08:00

230 lines
10 KiB
YAML
Raw 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.

# Lolly 配置文件
# 服务器配置(单服务器模式)
server:
listen: ":8080" # 监听地址
name: "localhost" # 服务器名称(虚拟主机匹配)
read_timeout: 30s # 读取超时0 表示不限制)
write_timeout: 30s # 写入超时0 表示不限制)
idle_timeout: 120s # 空闲超时0 表示不限制)
max_conns_per_ip: 1000 # 每 IP 最大连接数0 表示不限制)
max_requests_per_conn: 10000 # 每连接最大请求数0 表示不限制)
# 静态文件服务配置
static:
root: "/var/www/html" # 静态文件根目录
index: # 索引文件
- "index.html"
- "index.htm"
# 反向代理配置
# proxy:
# - path: /api # 匹配路径前缀
# targets: # 后端目标列表
# - url: http://backend1:8080
# weight: 3 # 权重(加权轮询时有效)
# - url: http://backend2:8080
# weight: 1
# load_balance: round_robin # 负载均衡算法: round_robin, weighted_round_robin, least_conn, ip_hash, consistent_hash
# hash_key: "ip" # 一致性哈希键(有效值: ip, uri, header:X-Name
# virtual_nodes: 150 # 一致性哈希虚拟节点数
# health_check: # 健康检查
# interval: 10s
# path: /health
# timeout: 5s
# timeout: # 超时配置
# connect: 5s # 连接超时
# read: 30s # 读取超时
# write: 30s # 写入超时
# headers: # 头部修改
# set_request: {X-Custom: value}
# set_response: {X-Server: lolly}
# remove: [X-Powered-By]
# cache: # 代理缓存
# enabled: false
# max_age: 60s
# cache_lock: true # 防止缓存击穿
# stale_while_revalidate: 30s
# SSL/TLS 配置
# ssl:
# cert: /path/to/cert.pem # 证书文件
# key: /path/to/key.pem # 私钥文件
# cert_chain: /path/to/chain.pem # 证书链文件
# protocols: # TLS 版本(有效值: TLSv1.2, TLSv1.3
# - "TLSv1.2"
# - "TLSv1.3"
# ciphers: [] # 加密套件(仅 TLS 1.2 有效)
# ocsp_stapling: false # OCSP Stapling
# hsts: # HTTP Strict Transport Security
# max_age: 31536000 # 过期时间(秒)
# include_sub_domains: true # 包含子域名
# preload: false # 加入 HSTS 预加载列表
# 安全配置
security:
# IP 访问控制
access:
allow: [] # 允许的 IP/CIDR 列表
deny: [] # 拒绝的 IP/CIDR 列表
default: "allow" # 默认动作(有效值: allow, deny
# 速率限制
rate_limit:
request_rate: 0 # 每秒请求数0 表示不限制)
burst: 0 # 突发上限
conn_limit: 0 # 连接数限制
key: "ip" # 限流 key 来源(有效值: ip, header
algorithm: "token_bucket" # 限流算法(有效值: token_bucket, sliding_window
sliding_window_mode: "approximate" # 滑动窗口模式(有效值: approximate, precise
sliding_window: 60 # 滑动窗口大小(秒)
# 认证配置type 为空时禁用)
auth:
type: "" # 认证类型(有效值: basic空表示禁用
require_tls: true # 启用时强制 HTTPS
algorithm: "bcrypt" # 密码哈希算法(有效值: bcrypt, argon2id
users: [] # 用户列表
realm: "Restricted Area" # 认证域
min_password_length: 8 # 密码最小长度
# 安全头部
headers:
x_frame_options: "DENY" # 防止点击劫持(有效值: DENY, SAMEORIGIN, 空表示禁用)
x_content_type_options: "nosniff" # 防止 MIME 嗅探
referrer_policy: "strict-origin-when-cross-origin" # 引用策略(有效值: no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
# content_security_policy: "default-src 'self'" # 内容安全策略 CSP
# permissions_policy: "geolocation=(), microphone=()" # 权限策略
# URL 重写规则
# rewrite:
# - pattern: "^/old/(.*)$" # 匹配模式(正则表达式)
# replacement: /new/$1 # 替换目标
# flag: last # 标志(有效值: last, redirect, permanent, break
# 响应压缩配置
compression:
type: "gzip" # 压缩类型(有效值: gzip, brotli, both空表示禁用
level: 6 # 压缩级别(范围 1-9值越大压缩率越高但速度越慢
min_size: 1024 # 最小压缩大小(字节,小于此值不压缩)
types: # 可压缩的 MIME 类型
- "text/html"
- "text/css"
- "text/javascript"
- "application/json"
- "application/javascript"
gzip_static: true # 启用预压缩文件支持(检测 .gz 文件)
gzip_static_extensions: # 预压缩文件扩展名
- ".html"
- ".css"
- ".js"
- ".json"
- ".xml"
- ".svg"
# 多虚拟主机模式(可选,每个虚拟主机支持完整的 server 配置)
# servers:
# - listen: ":8080" # 监听地址
# name: "api.example.com" # 服务器名称(用于虚拟主机匹配)
# read_timeout: 30s # 读取超时0 表示不限制)
# write_timeout: 30s # 写入超时0 表示不限制)
# idle_timeout: 120s # 空闲超时0 表示不限制)
# max_conns_per_ip: 1000 # 每 IP 最大连接数0 表示不限制)
# max_requests_per_conn: 10000 # 每连接最大请求数0 表示不限制)
# static: # 静态文件配置
# root: /var/www/api
# index: [index.html]
# proxy: # 反向代理配置
# - path: /api
# targets:
# - url: http://backend:8080
# load_balance: round_robin
# ssl: # SSL/TLS 配置
# cert: /path/to/api.cert.pem
# key: /path/to/api.key.pem
# protocols: [TLSv1.2, TLSv1.3]
# hsts:
# max_age: 31536000
# include_sub_domains: true
# security: # 安全配置
# access:
# default: allow
# rate_limit:
# request_rate: 100
# headers:
# x_frame_options: DENY
# compression: # 响应压缩配置
# type: gzip
# level: 6
# - listen: ":8443" # 另一个虚拟主机
# name: "static.example.com"
# static:
# root: /var/www/static
# index: [index.html, index.htm]
# ssl:
# cert: /path/to/static.cert.pem
# key: /path/to/static.key.pem
# compression:
# type: gzip
# SSL/TLS 默认配置说明(未配置证书时不启用)
# 默认 TLS 协议: TLSv1.2, TLSv1.3(不支持 TLSv1.0/1.1
# 默认 HSTS 配置: max_age=315360001年, include_sub_domains=true
# HTTP/3 (QUIC) 配置(可选)
# http3:
# enabled: false # 是否启用 HTTP/3
# listen: ":443" # UDP 监听地址
# max_streams: 100 # 最大并发流数
# idle_timeout: 30s # 空闲超时
# enable_0rtt: false # 启用 0-RTT 快速连接
# TCP/UDP Stream 代理配置(可选)
# stream:
# - listen: "3306" # 监听地址
# protocol: "tcp" # 协议类型(有效值: tcp, udp
# upstream:
# targets: # 上游目标列表
# - addr: "mysql1:3306" # 目标地址
# weight: 3 # 权重(加权轮询时有效)
# - addr: "mysql2:3306"
# weight: 1
# load_balance: "round_robin" # 负载均衡算法(有效值: round_robin, weighted_round_robin, least_conn, ip_hash
# 日志配置
logging:
format: "text" # 全局日志格式(有效值: text, json控制启动/停止日志格式
access:
path: "" # 日志文件路径(空表示输出到 stdout
format: '$remote_addr - $remote_user [$time] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"' # 访问日志格式,近似 nginx combined
# 支持变量: $remote_addr, $remote_user, $request, $status, $body_bytes_sent, $request_time, $http_referer, $http_user_agent, $time
# 特殊值 "json" 输出结构化 JSON
error:
path: "" # 日志文件路径(空表示输出到 stderr
level: "info" # 日志级别(有效值: debug, info, warn, error级别越高日志越少
# 性能配置
performance:
goroutine_pool: # Goroutine 池(处理并发请求)
enabled: false # 是否启用
max_workers: 1000 # 最大 worker 数
min_workers: 10 # 最小 worker 数(预热)
idle_timeout: 60s # 空闲超时
file_cache: # 静态文件缓存
max_entries: 10000 # 最大缓存条目
max_size: 268435456 # 内存上限字节256MB
inactive: 20s # 未访问淘汰时间
lru_eviction: true # 启用 LRU 淘汰
transport: # HTTP Transport 连接池
max_idle_conns: 100 # 最大空闲连接
max_idle_conns_per_host: 32 # 每主机空闲连接
idle_conn_timeout: 90s # 空闲超时
max_conns_per_host: 0 # 每主机最大连接0 表示不限制)
# 监控配置
monitoring:
status:
path: "/_status" # 状态端点路径
allow: # 允许访问的 IP
- "127.0.0.1"