Files
waf-platform/EdgeCommon/pkg/serverconfigs/global_server_config.go
2026-02-13 22:36:17 +08:00

117 lines
6.6 KiB
Go
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.

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package serverconfigs
type LnRequestSchedulingMethod = string
const (
LnRequestSchedulingMethodRandom LnRequestSchedulingMethod = "random"
LnRequestSchedulingMethodURLMapping LnRequestSchedulingMethod = "urlMapping"
)
const (
DefaultTCPPortRangeMin = 10000
DefaultTCPPortRangeMax = 40000
)
func NewGlobalServerConfig() *GlobalServerConfig {
var config = &GlobalServerConfig{}
config.HTTPAll.SupportsLowVersionHTTP = true
config.HTTPAll.EnableServerAddrVariable = false
config.HTTPAll.LnRequestSchedulingMethod = LnRequestSchedulingMethodURLMapping
config.HTTPAccessLog.IsOn = true
config.HTTPAccessLog.EnableRequestHeaders = true
config.HTTPAccessLog.EnableResponseHeaders = true
config.HTTPAccessLog.EnableCookies = true
config.HTTPAccessLog.EnableServerNotFound = true
config.HTTPAccessLog.Rotate = NewDefaultAccessLogRotateConfig()
config.Log.RecordServerError = false
config.Performance.AutoWriteTimeout = false
config.Performance.AutoReadTimeout = false
config.Stat.Upload.MaxCities = 32
config.Stat.Upload.MaxProviders = 32
config.Stat.Upload.MaxSystems = 64
config.Stat.Upload.MaxBrowsers = 64
return config
}
// GlobalServerConfig 全局的服务配置
type GlobalServerConfig struct {
HTTPAll struct {
MatchDomainStrictly bool `yaml:"matchDomainStrictly" json:"matchDomainStrictly"` // 是否严格匹配域名
AllowMismatchDomains []string `yaml:"allowMismatchDomains" json:"allowMismatchDomains"` // 允许的不匹配的域名
AllowNodeIP bool `yaml:"allowNodeIP" json:"allowNodeIP"` // 允许IP直接访问
NodeIPShowPage bool `yaml:"nodeIPShowPage" json:"nodeIPShowPage"` // 访问IP地址是否显示页面
NodeIPPageHTML string `yaml:"nodeIPPageHTML" json:"nodeIPPageHTML"` // 访问IP地址页面内容
DefaultDomain string `yaml:"defaultDomain" json:"defaultDomain"` // 默认的域名
DomainMismatchAction *DomainMismatchAction `yaml:"domainMismatchAction" json:"domainMismatchAction"` // 不匹配时采取的动作
SupportsLowVersionHTTP bool `yaml:"supportsLowVersionHTTP" json:"supportsLowVersionHTTP"` // 是否启用低版本HTTP
MatchCertFromAllServers bool `yaml:"matchCertFromAllServers" json:"matchCertFromAllServers"` // 从所有服务中匹配证书(不要轻易开启!)
ForceLnRequest bool `yaml:"forceLnRequest" json:"forceLnRequest"` // 强制从Ln请求内容
LnRequestSchedulingMethod LnRequestSchedulingMethod `yaml:"lnRequestSchedulingMethod" json:"lnRequestSchedulingMethod"` // Ln请求调度方法
ServerName string `yaml:"serverName" json:"serverName"` // Server名称
EnableServerAddrVariable bool `yaml:"enableServerAddrVariable" json:"enableServerAddrVariable"` // 是否支持${serverAddr}变量
XFFMaxAddresses int `yaml:"xffMaxAddresses" json:"xffMaxAddresses"` // XFF中最多的地址数
DomainAuditingIsOn bool `yaml:"domainAuditingIsOn" json:"domainAuditingIsOn"` // 域名是否需要审核
DomainAuditingPrompt string `yaml:"domainAuditingPrompt" json:"domainAuditingPrompt"` // 域名审核的提示
RequestOriginsWithEncodings bool `yaml:"requestOriginsWithEncodings" json:"requestOriginsWithEncodings"` // 使用使用压缩编码回源
} `yaml:"httpAll" json:"httpAll"` // HTTP统一配置
TCPAll struct {
PortRangeMin int `yaml:"portRangeMin" json:"portRangeMin"` // 最小端口
PortRangeMax int `yaml:"portRangeMax" json:"portRangeMax"` // 最大端口
DenyPorts []int `yaml:"denyPorts" json:"denyPorts"` // 禁止使用的端口
} `yaml:"tcpAll" json:"tcpAll"`
HTTPAccessLog struct {
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用此功能
EnableRequestHeaders bool `yaml:"enableRequestHeaders" json:"enableRequestHeaders"` // 记录请求Header
CommonRequestHeadersOnly bool `yaml:"commonRequestHeadersOnly" json:"commonRequestHeadersOnly"` // 只保留通用Header
EnableResponseHeaders bool `yaml:"enableResponseHeaders" json:"enableResponseHeaders"` // 记录响应Header
EnableCookies bool `yaml:"enableCookies" json:"enableCookies"` // 记录Cookie
EnableServerNotFound bool `yaml:"enableServerNotFound" json:"enableServerNotFound"` // 记录服务找不到的日志
WriteTargets *AccessLogWriteTargets `yaml:"writeTargets" json:"writeTargets"` // 写入目标:文件/MySQL/ClickHouse双写/单写)
FilePath string `yaml:"filePath" json:"filePath"` // 公用日志策略文件路径(用于节点侧复用)
Rotate *AccessLogRotateConfig `yaml:"rotate" json:"rotate"` // 本地日志轮转配置lumberjack
} `yaml:"httpAccessLog" json:"httpAccessLog"` // 访问日志配置
Stat struct {
Upload struct {
MaxCities int16 `yaml:"maxCities" json:"maxCities"` // 最大区域数量
MaxProviders int16 `yaml:"maxProviders" json:"maxProviders"` // 最大运营商数量
MaxSystems int16 `yaml:"maxSystems" json:"maxSystems"` // 最大操作系统数量
MaxBrowsers int16 `yaml:"maxBrowsers" json:"maxBrowsers"` // 最大浏览器数量
} `yaml:"upload" json:"upload"` // 上传相关设置
} `yaml:"stat" json:"stat"` // 统计相关配置
Performance struct {
Debug bool `yaml:"debug" json:"debug"` // Debug模式
AutoWriteTimeout bool `yaml:"autoWriteTimeout" json:"autoWriteTimeout"` // 是否自动写超时
AutoReadTimeout bool `yaml:"autoReadTimeout" json:"autoReadTimeout"` // 是否自动读超时
} `yaml:"performance" json:"performance"` // 性能
Log struct {
RecordServerError bool `yaml:"recordServerError" json:"recordServerError"` // 记录服务错误到运行日志
} `yaml:"log" json:"log"` // 运行日志配置
}
func (this *GlobalServerConfig) Init() error {
// 未找到域名时的动作
if this.HTTPAll.DomainMismatchAction != nil {
err := this.HTTPAll.DomainMismatchAction.Init()
if err != nil {
return err
}
}
return nil
}