Documentation
¶
Index ¶
- type AccessControlConfig
- type CacheConfig
- type IncludeFile
- type Listen
- type PHPVhost
- type Proxy
- type ProxyVhost
- type RateLimit
- type RealIP
- type Redirect
- type RedirectType
- type ResponseHeaderConfig
- type RetryConfig
- type SSLBackendConfig
- type SSLConfig
- type StaticVhost
- type TimeoutConfig
- type Upstream
- type Vhost
- type VhostPHP
- type VhostProxy
- type VhostRedirect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessControlConfig ¶
type AccessControlConfig struct {
// 允许的 IP/CIDR 列表 (allow)
Allow []string `form:"allow" json:"allow"`
// 拒绝的 IP/CIDR 列表 (deny)
Deny []string `form:"deny" json:"deny"`
}
AccessControlConfig IP 访问控制配置
type CacheConfig ¶
type CacheConfig struct {
// 缓存时长,状态码 -> 时长,如: {"200 302": "10m", "404": "1m", "any": "5m"}
Valid map[string]string `form:"valid" json:"valid"`
// 不缓存条件 (proxy_cache_bypass + proxy_no_cache)
// 常用值: "$cookie_nocache", "$arg_nocache", "$http_pragma", "$http_authorization"
NoCacheConditions []string `form:"no_cache_conditions" json:"no_cache_conditions"`
// 过期缓存使用策略 (proxy_cache_use_stale)
// 可选值: "error", "timeout", "updating", "http_500", "http_502", "http_503", "http_504"
UseStale []string `form:"use_stale" json:"use_stale"`
// 后台更新 (proxy_cache_background_update)
BackgroundUpdate bool `form:"background_update" json:"background_update"`
// 缓存锁 (proxy_cache_lock),防止缓存击穿
Lock bool `form:"lock" json:"lock"`
// 最小请求次数 (proxy_cache_min_uses),请求 N 次后才缓存
MinUses int `form:"min_uses" json:"min_uses"`
// 缓存方法 (proxy_cache_methods),默认 GET HEAD
Methods []string `form:"methods" json:"methods"`
// 自定义缓存键 (proxy_cache_key)
Key string `form:"key" json:"key"`
}
CacheConfig 缓存配置
type IncludeFile ¶
type IncludeFile struct {
Path string `json:"path"` // 文件路径
Comment []string `json:"comment"` // 注释说明
}
IncludeFile 包含文件配置
type Listen ¶
type Listen struct {
Address string `form:"address" json:"address"` // 监听地址,如: "80", "0.0.0.0:80", "[::]:443"
Args []string `form:"args" json:"args"` // 其他参数,如: ["default_server", "ssl", "quic"]
}
Listen 监听配置
type Proxy ¶
type Proxy struct {
Location string `form:"location" json:"location" validate:"required"` // 匹配路径,如: "/", "/api", "~ ^/api/v[0-9]+/"
Pass string `form:"pass" json:"pass" validate:"required"` // 代理地址,如: "http://example.com", "http://backend"
Host string `form:"host" json:"host"` // 代理 Host,如: "example.com"
SNI string `form:"sni" json:"sni"` // 代理 SNI,如: "example.com"
Cache *CacheConfig `form:"cache" json:"cache"` // 缓存配置,nil 表示禁用缓存
Buffering bool `form:"buffering" json:"buffering"` // 是否启用缓冲
Resolver []string `form:"resolver" json:"resolver"` // 自定义 DNS 解析器配置,如: ["8.8.8.8", "ipv6=off"]
ResolverTimeout time.Duration `form:"resolver_timeout" json:"resolver_timeout"` // DNS 解析超时时间,如: 5 * time.Second
Headers map[string]string `form:"headers" json:"headers"` // 自定义请求头,如: map["X-Custom-Header"] = "value"
Replaces map[string]string `form:"replaces" json:"replaces"` // 响应内容替换,如: map["/old"] = "/new"
HTTPVersion string `form:"http_version" json:"http_version"` // HTTP 协议版本 (proxy_http_version),可选: "1.0", "1.1", "2"
Timeout *TimeoutConfig `form:"timeout" json:"timeout"` // 超时配置
Retry *RetryConfig `form:"retry" json:"retry"` // 重试配置
ClientMaxBodySize int64 `form:"client_max_body_size" json:"client_max_body_size"` // 请求体大小限制 (client_max_body_size),单位字节,0 表示使用全局配置
SSLBackend *SSLBackendConfig `form:"ssl_backend" json:"ssl_backend"` // SSL 后端验证配置
ResponseHeaders *ResponseHeaderConfig `form:"response_headers" json:"response_headers"` // 响应头修改配置
AccessControl *AccessControlConfig `form:"access_control" json:"access_control"` // IP 访问控制配置
}
Proxy 反向代理配置
type ProxyVhost ¶
type ProxyVhost interface {
Vhost
VhostRedirect
VhostProxy
}
ProxyVhost 反向代理虚拟主机接口
type RateLimit ¶
type RateLimit struct {
PerServer int `json:"per_server"` // 站点最大并发数 (limit_conn perserver X)
PerIP int `json:"per_ip"` // 单 IP 最大并发数 (limit_conn perip X)
Rate int `json:"rate"` // 流量限制,单位 KB (limit_rate Xk)
}
RateLimit 限流限速配置
type RealIP ¶
type RealIP struct {
From []string `json:"from"` // 可信 IP 来源列表 (set_real_ip_from)
Header string `json:"header"` // 真实 IP 头 (real_ip_header),如: X-Real-IP, X-Forwarded-For
Recursive bool `json:"recursive"` // 递归搜索 (real_ip_recursive)
}
RealIP 真实 IP 配置
type Redirect ¶
type Redirect struct {
Type RedirectType `json:"type"` // 重定向类型
From string `json:"from"` // 源地址,如: "example.com", "http://example.com", "/old"
To string `json:"to"` // 目标地址,如: "https://example.com"
KeepURI bool `json:"keep_uri"` // 是否保持 URI 不变(即保留请求参数)
StatusCode int `json:"status_code"` // 自定义状态码,如: 301, 302, 307, 308,默认 308
}
Redirect 重定向配置
type RedirectType ¶
type RedirectType string
RedirectType 重定向类型
const ( RedirectType404 RedirectType = "404" // 404 重定向 RedirectTypeHost RedirectType = "host" // 主机名重定向 RedirectTypeURL RedirectType = "url" // URL 重定向 )
type ResponseHeaderConfig ¶
type ResponseHeaderConfig struct {
// 隐藏的响应头 (proxy_hide_header)
Hide []string `form:"hide" json:"hide"`
// 添加的响应头 (add_header),key -> value
// 值可以包含变量,如 $upstream_cache_status
Add map[string]string `form:"add" json:"add"`
}
ResponseHeaderConfig 响应头修改配置
type RetryConfig ¶
type RetryConfig struct {
// 触发重试的条件 (proxy_next_upstream)
// 可选值: "error", "timeout", "invalid_header", "http_500", "http_502", "http_503", "http_504", "http_429", "non_idempotent", "off"
Conditions []string `form:"conditions" json:"conditions"`
// 最大重试次数 (proxy_next_upstream_tries),0 表示不限制
Tries int `form:"tries" json:"tries"`
// 重试超时时间 (proxy_next_upstream_timeout),0 表示不限制
Timeout time.Duration `form:"timeout" json:"timeout"`
}
RetryConfig 重试配置
type SSLBackendConfig ¶
type SSLBackendConfig struct {
Verify bool `form:"verify" json:"verify"` // proxy_ssl_verify on/off
TrustedCertificate string `form:"trusted_certificate" json:"trusted_certificate"` // proxy_ssl_trusted_certificate 路径
VerifyDepth int `form:"verify_depth" json:"verify_depth"` // proxy_ssl_verify_depth,默认 1
}
SSLBackendConfig SSL 后端验证配置
type SSLConfig ¶
type SSLConfig struct {
Cert string `json:"cert"` // 证书路径
Key string `json:"key"` // 私钥路径
Protocols []string `json:"protocols"` // 支持的协议,如: ["TLSv1.2", "TLSv1.3"]
Ciphers string `json:"ciphers"` // 加密套件
// 高级选项
HSTS bool `json:"hsts"` // HTTP 严格传输安全
OCSP bool `json:"ocsp"` // OCSP Stapling
HTTPRedirect bool `json:"http_redirect"` // HTTP 强制跳转 HTTPS
AltSvc string `json:"alt_svc"` // Alt-Svc 配置,如: 'h3=":443"; ma=86400'
}
SSLConfig SSL/TLS 配置
type TimeoutConfig ¶
type TimeoutConfig struct {
Connect time.Duration `form:"connect" json:"connect"` // proxy_connect_timeout,默认 60s
Read time.Duration `form:"read" json:"read"` // proxy_read_timeout,默认 60s
Send time.Duration `form:"send" json:"send"` // proxy_send_timeout,默认 60s
}
TimeoutConfig 超时配置
type Upstream ¶
type Upstream struct {
Name string `form:"name" json:"name" validate:"required"` // 上游名称,如: "backend"
Servers map[string]string `form:"servers" json:"servers" validate:"required"` // 上游服务器及配置,如: map["server1"] = "weight=5 resolve"
Algo string `form:"algo" json:"algo"` // 负载均衡算法,如: "least_conn", "ip_hash"
Keepalive int `form:"keepalive" json:"keepalive"` // 保持连接数,如: 32
Resolver []string `form:"resolver" json:"resolver"` // 自定义 DNS 解析器配置,如: ["8.8.8.8", "ipv6=off"]
ResolverTimeout time.Duration `form:"resolver_timeout" json:"resolver_timeout"` // DNS 解析超时时间,如: 5 * time.Second
}
Upstream 上游服务器配置
type Vhost ¶
type Vhost interface {
// Enable 取启用状态
Enable() bool
// SetEnable 设置启用状态
SetEnable(enable bool) error
// Listen 取监听配置
Listen() []Listen
// SetListen 设置监听配置
SetListen(listen []Listen) error
// ServerName 取服务器名称,如: ["example.com", "www.example.com"]
ServerName() []string
// SetServerName 设置服务器名称
SetServerName(serverName []string) error
// Index 取默认首页,如: ["index.php", "index.html"]
Index() []string
// SetIndex 设置默认首页
SetIndex(index []string) error
// Root 取网站根目录,如: "/opt/ace/sites/example/public"
Root() string
// SetRoot 设置网站根目录
SetRoot(root string) error
// Includes 取包含的文件配置
Includes() []IncludeFile
// SetIncludes 设置包含的文件配置
SetIncludes(includes []IncludeFile) error
// AccessLog 取访问日志路径,如: "/opt/ace/sites/example/log/access.log"
AccessLog() string
// SetAccessLog 设置访问日志路径
SetAccessLog(accessLog string) error
// ErrorLog 取错误日志路径,如: "/opt/ace/sites/example/log/error.log"
ErrorLog() string
// SetErrorLog 设置错误日志路径
SetErrorLog(errorLog string) error
// Save 保存配置到文件
Save() error
// Reset 重置配置为默认值
Reset() error
// SSL 取 SSL 启用状态
SSL() bool
// SSLConfig 取 SSL 配置
SSLConfig() *SSLConfig
// SetSSLConfig 设置 SSL 配置(自动启用 HTTPS)
SetSSLConfig(cfg *SSLConfig) error
// ClearSSL 清除 SSL 配置
ClearSSL() error
// RateLimit 取限流限速配置
RateLimit() *RateLimit
// SetRateLimit 设置限流限速配置
SetRateLimit(limit *RateLimit) error
// ClearRateLimit 清除限流限速配置
ClearRateLimit() error
// BasicAuth 取基本认证配置
BasicAuth() map[string]string
// SetBasicAuth 设置基本认证
SetBasicAuth(auth map[string]string) error
// ClearBasicAuth 清除基本认证
ClearBasicAuth() error
// RealIP 取真实 IP 配置
RealIP() *RealIP
// SetRealIP 设置真实 IP 配置
SetRealIP(realIP *RealIP) error
// ClearRealIP 清除真实 IP 配置
ClearRealIP() error
// Config 取指定名称的配置内容
// type 可选值: "site", "shared"
Config(name string, typ string) string
// SetConfig 设置指定名称的配置内容
// type 可选值: "site", "shared"
SetConfig(name string, typ string, content string) error
// RemoveConfig 清除指定名称的配置内容
// type 可选值: "site", "shared"
RemoveConfig(name string, typ string) error
}
Vhost 虚拟主机通用接口
type VhostPHP ¶
type VhostPHP interface {
// PHP 取 PHP 版本,如: 84, 81, 80, 0 表示未启用 PHP
PHP() uint
// SetPHP 设置 PHP 版本
SetPHP(version uint) error
}
VhostPHP PHP 相关接口
type VhostProxy ¶
type VhostProxy interface {
// Proxies 取所有反向代理配置
Proxies() []Proxy
// SetProxies 设置反向代理配置
SetProxies(proxies []Proxy) error
// ClearProxies 清除所有反向代理配置
ClearProxies() error
// Upstreams 取上游服务器配置
Upstreams() []Upstream
// SetUpstreams 设置上游服务器配置
SetUpstreams(upstreams []Upstream) error
// ClearUpstreams 清除所有上游服务器配置
ClearUpstreams() error
}
VhostProxy 反向代理相关接口
type VhostRedirect ¶
type VhostRedirect interface {
// Redirects 取所有重定向配置
Redirects() []Redirect
// SetRedirects 设置重定向
SetRedirects(redirects []Redirect) error
}
VhostRedirect 重定向相关接口
Click to show internal directories.
Click to hide internal directories.