Documentation
¶
Index ¶
- func IsPlatformDomain(domain, coreDomain string) bool
- func NeedsSeparateTLSPolicy(domain, coreDomain string) bool
- type AdminConfig
- type AppsConfig
- type AutoHTTPSConfig
- type AutomationConfig
- type AutomationPolicy
- func NewDNS01Policy(id string, subjects []string, providerName, secretID, secretKey string) AutomationPolicy
- func NewHTTP01Policy(id string, subjects []string) AutomationPolicy
- func NewSingleDomainHTTP01Policy(domain string) AutomationPolicy
- func NewWildcardDNS01Policy(coreDomain, providerName, secretID, secretKey string) AutomationPolicy
- type CaddyConfig
- type CertificateInfo
- type ChallengeConfig
- type Client
- func (c *Client) AddCustomDomain(domain, sitePath string, skipCheck bool) error
- func (c *Client) AddStaticSite(domain, sitePath string) error
- func (c *Client) AddTLSPolicy(policy AutomationPolicy) error
- func (c *Client) CheckDomainReadiness(domain string) (*DomainCheckResult, error)
- func (c *Client) ExportConfig(outputPath string) error
- func (c *Client) GenerateTLSConfig() *TLSConfig
- func (c *Client) GetCertificateStatus(domain string) (*CertificateInfo, error)
- func (c *Client) GetConfig() (map[string]interface{}, error)
- func (c *Client) GetPID() (int, error)
- func (c *Client) GetTLSPolicies() ([]AutomationPolicy, error)
- func (c *Client) IsRunning() bool
- func (c *Client) Ping() error
- func (c *Client) RemoveCustomDomain(domain string) error
- func (c *Client) RemoveStaticSite(domain string) error
- func (c *Client) RemoveTLSPolicy(policyID string) error
- func (c *Client) SetupPlatformWildcard() error
- func (c *Client) StartServer() error
- func (c *Client) StartServerBackground() error
- func (c *Client) Stop() error
- type Config
- type DNSChallenge
- type DNSProvider
- type DomainCheckResult
- type DomainChecker
- type HTTPChallenge
- type HTTPConfig
- type HandleConfig
- type Issuer
- type MatchHost
- type Route
- type ServerConfig
- type TLSConfig
- type Upstream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPlatformDomain ¶ added in v0.2.5
IsPlatformDomain 判断域名是否为平台域名(使用 Wildcard 证书) 平台域名包括:coreDomain 本身,以及 *.coreDomain 的所有子域名 例如:mdfriday.com, user123.mdfriday.com, cdb.mdfriday.com 都是平台域名
func NeedsSeparateTLSPolicy ¶ added in v0.2.5
NeedsSeparateTLSPolicy 判断域名是否需要单独的 TLS 策略 只有非平台域名(用户自定义域名)才需要单独的 HTTP-01 策略
Types ¶
type AdminConfig ¶
type AdminConfig struct {
Listen string `json:"listen"`
}
AdminConfig Caddy Admin 配置
type AppsConfig ¶
type AppsConfig struct {
HTTP *HTTPConfig `json:"http"`
TLS *TLSConfig `json:"tls,omitempty"`
}
AppsConfig Caddy Apps 配置
type AutoHTTPSConfig ¶
type AutoHTTPSConfig struct {
Disable bool `json:"disable,omitempty"` // 禁用自动 HTTPS
}
AutoHTTPSConfig 自动 HTTPS 配置
type AutomationConfig ¶ added in v0.2.5
type AutomationConfig struct {
Policies []AutomationPolicy `json:"policies,omitempty"`
}
AutomationConfig 自动证书管理配置
type AutomationPolicy ¶ added in v0.2.5
type AutomationPolicy struct {
ID string `json:"@id,omitempty"`
Subjects []string `json:"subjects"`
Issuers []Issuer `json:"issuers,omitempty"`
}
AutomationPolicy 证书策略
func NewDNS01Policy ¶ added in v0.2.5
func NewDNS01Policy(id string, subjects []string, providerName, secretID, secretKey string) AutomationPolicy
NewDNS01Policy 创建 DNS-01 策略(用于平台域名的 Wildcard 证书)
前提条件: 使用 DNS-01 challenge 需要 Caddy 在构建时包含对应的 DNS provider 插件。 对于腾讯云 DNS(DNSPod),需要使用 xcaddy 构建包含 caddy-dns/tencentcloud 插件的 Caddy 实例:
# 在 Ubuntu 上安装 xcaddy go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest # 构建包含腾讯云 DNS 插件的 Caddy xcaddy build --with github.com/caddy-dns/tencentcloud # 构建后的 caddy 二进制文件将支持 tencentcloud DNS-01 challenge
注意:DNSPod 已被腾讯云收购,原 github.com/caddy-dns/dnspod 已过时且不兼容新版 libdns。 请使用 github.com/caddy-dns/tencentcloud,provider name 为 "tencentcloud"。 凭据直接在配置中传递(环境变量方式在某些版本不工作)
如果使用官方预编译的 Caddy 二进制文件,DNS-01 challenge 将无法工作。
func NewHTTP01Policy ¶ added in v0.2.5
func NewHTTP01Policy(id string, subjects []string) AutomationPolicy
NewHTTP01Policy 创建 HTTP-01 策略(用于用户自定义域名)
func NewSingleDomainHTTP01Policy ¶ added in v0.2.5
func NewSingleDomainHTTP01Policy(domain string) AutomationPolicy
NewSingleDomainHTTP01Policy 创建单域名 HTTP-01 策略 用于用户自定义域名(每个 License 最多一个自定义域名)
func NewWildcardDNS01Policy ¶ added in v0.2.5
func NewWildcardDNS01Policy(coreDomain, providerName, secretID, secretKey string) AutomationPolicy
NewWildcardDNS01Policy 创建 Wildcard DNS-01 策略 用于平台域名(如 mdfriday.com 和 *.mdfriday.com)
前提条件:需要构建包含 DNS provider 插件的 Caddy 实例(参见 NewDNS01Policy 注释) 凭据直接在配置中传递
type CaddyConfig ¶
type CaddyConfig struct {
Admin *AdminConfig `json:"admin"`
Apps *AppsConfig `json:"apps"`
}
CaddyConfig Caddy 完整配置结构
type CertificateInfo ¶
type CertificateInfo struct {
Domain string `json:"domain"`
Status string `json:"status"` // "issued", "pending", "failed"
NotBefore time.Time `json:"not_before"`
NotAfter time.Time `json:"not_after"`
Issuer string `json:"issuer"`
Error string `json:"error,omitempty"`
}
CertificateInfo SSL 证书信息
type ChallengeConfig ¶ added in v0.2.5
type ChallengeConfig struct {
DNS *DNSChallenge `json:"dns,omitempty"`
HTTP *HTTPChallenge `json:"http,omitempty"`
}
ChallengeConfig ACME Challenge 配置
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client Caddy HTTP 客户端
func (*Client) AddCustomDomain ¶ added in v0.2.5
AddCustomDomain 添加用户自定义域名(单域名模式) 每个 License 只能有一个自定义域名,因此每次只处理单个域名 skipCheck: 是否跳过域名预检测(仅开发环境使用)
注意:此方法仅用于用户自定义域名(如 hello.com),不适用于平台 subdomain。 平台 subdomain(如 user123.mdfriday.com)应使用 AddStaticSite,因为它们使用 Wildcard 证书。
func (*Client) AddStaticSite ¶
AddStaticSite 动态添加自定义域名的静态站点 domain: 自定义域名 (如 example.com) sitePath: 静态站点文件路径 (如 /web/sites/example-com) A mdfriday.com → <server-ip> A *.mdfriday.com → <server-ip>
注意:为确保具体域名优先于通配符匹配,采用以下策略: 1. 删除通配符 route 2. 添加新 route 3. 重新添加通配符 route(保持在最后)
func (*Client) AddTLSPolicy ¶ added in v0.2.5
func (c *Client) AddTLSPolicy(policy AutomationPolicy) error
AddTLSPolicy 添加 TLS 证书策略
func (*Client) CheckDomainReadiness ¶ added in v0.2.5
func (c *Client) CheckDomainReadiness(domain string) (*DomainCheckResult, error)
CheckDomainReadiness 检查域名是否就绪(供 API 层调用)
func (*Client) ExportConfig ¶
ExportConfig 导出当前 Caddy 的配置到文件
func (*Client) GenerateTLSConfig ¶ added in v0.2.5
GenerateTLSConfig 生成 TLS 配置(用于启动时) 凭据直接在配置中传递
func (*Client) GetCertificateStatus ¶
func (c *Client) GetCertificateStatus(domain string) (*CertificateInfo, error)
GetCertificateStatus 查询域名的 SSL 证书状态 domain: 要查询的域名
func (*Client) GetTLSPolicies ¶ added in v0.2.5
func (c *Client) GetTLSPolicies() ([]AutomationPolicy, error)
GetTLSPolicies 获取所有 TLS 证书策略
func (*Client) RemoveCustomDomain ¶ added in v0.2.5
RemoveCustomDomain 移除用户自定义域名 注意:平台 subdomain 应使用 RemoveStaticSite
func (*Client) RemoveStaticSite ¶
RemoveStaticSite 移除自定义域名的静态站点
func (*Client) RemoveTLSPolicy ¶ added in v0.2.5
RemoveTLSPolicy 移除 TLS 证书策略
func (*Client) SetupPlatformWildcard ¶ added in v0.2.5
SetupPlatformWildcard 设置平台域名的 Wildcard 证书 使用 DNS-01 challenge 注意:凭据直接在配置中传递
func (*Client) StartServer ¶
StartServer 启动 Caddy 服务器 使用默认配置启动,包含核心域名和 CouchDB 的反向代理
func (*Client) StartServerBackground ¶
StartServerBackground 后台启动 Caddy 服务器 启动后立即返回,将 PID 写入 PidFile
type Config ¶
type Config struct {
AdminAPI string `json:"admin_api"` // Caddy Admin API 地址 (如 http://127.0.0.1:2019)
ConfigPath string `json:"config_path"` // Caddy 配置文件路径
BinaryPath string `json:"binary_path"` // Caddy 二进制文件路径
DefaultBackend string `json:"default_backend"` // 默认后端服务地址 (如 127.0.0.1:1314)
CouchDBBackend string `json:"couchdb_backend"` // CouchDB 服务地址 (如 127.0.0.1:5984)
CoreDomain string `json:"core_domain"` // 核心域名 (如 mdfriday.site)
PidFile string `json:"pid_file"` // PID 文件路径 (用于后台运行)
LogFile string `json:"log_file"` // 日志文件路径
DNSPodToken string `json:"dnspod_token"` // 腾讯云 DNS API Token (格式: SecretId,SecretKey,用于 DNS-01 challenge)
ServerIP string `json:"server_ip"` // 服务器公网 IP (用于域名检查)
}
Config Caddy 配置
type DNSChallenge ¶ added in v0.2.5
type DNSChallenge struct {
Provider *DNSProvider `json:"provider"`
}
DNSChallenge DNS-01 Challenge 配置
type DNSProvider ¶ added in v0.2.5
type DNSProvider struct {
Name string `json:"name"`
SecretId string `json:"SecretId,omitempty"`
SecretKey string `json:"SecretKey,omitempty"`
Region string `json:"Region,omitempty"`
SessionToken string `json:"SessionToken,omitempty"`
}
DNSProvider DNS 提供商配置 腾讯云 DNS (tencentcloud) 凭据直接在配置中指定 注意:环境变量方式在某些 Caddy 版本中不工作,因此直接在配置中传递凭据 JSON 字段名必须使用 PascalCase(与 caddy-dns/tencentcloud 插件保持一致)
type DomainCheckResult ¶ added in v0.2.5
type DomainCheckResult struct {
Domain string `json:"domain"`
DNSValid bool `json:"dns_valid"`
ResolvedIPs []string `json:"resolved_ips"`
HTTPReachable bool `json:"http_reachable"`
Error string `json:"error,omitempty"`
Ready bool `json:"ready"`
}
DomainCheckResult 域名检查结果
type DomainChecker ¶ added in v0.2.5
DomainChecker 域名检查器
func NewDomainChecker ¶ added in v0.2.5
func NewDomainChecker(serverIP string) *DomainChecker
NewDomainChecker 创建域名检查器
func (*DomainChecker) CheckAll ¶ added in v0.2.5
func (c *DomainChecker) CheckAll(domain string) *DomainCheckResult
CheckAll 执行完整的域名检查 依次检查 DNS 和 HTTP,全部通过则 Ready=true
func (*DomainChecker) CheckDNS ¶ added in v0.2.5
func (c *DomainChecker) CheckDNS(domain string) *DomainCheckResult
CheckDNS 检查域名 DNS 解析 验证域名是否解析到指定的服务器 IP
func (*DomainChecker) CheckDNSOnly ¶ added in v0.2.5
func (c *DomainChecker) CheckDNSOnly(domain string) *DomainCheckResult
CheckDNSOnly 仅检查 DNS(不检查 HTTP) 用于快速验证 DNS 配置
func (*DomainChecker) CheckHTTP ¶ added in v0.2.5
func (c *DomainChecker) CheckHTTP(domain string) *DomainCheckResult
CheckHTTP 检查 HTTP 可达性 验证域名的 80 端口是否可以访问(用于 HTTP-01 challenge)
type HTTPChallenge ¶ added in v0.2.5
type HTTPChallenge struct {
}
HTTPChallenge HTTP-01 Challenge 配置
type HTTPConfig ¶
type HTTPConfig struct {
Servers map[string]*ServerConfig `json:"servers"`
}
HTTPConfig HTTP App 配置
type HandleConfig ¶
type HandleConfig struct {
Handler string `json:"handler"`
Upstreams []Upstream `json:"upstreams,omitempty"` // for reverse_proxy
Root string `json:"root,omitempty"` // for file_server
StatusCode int `json:"status_code,omitempty"` // for static_response
}
HandleConfig 处理器配置
type Issuer ¶ added in v0.2.5
type Issuer struct {
Module string `json:"module"`
Challenges *ChallengeConfig `json:"challenges,omitempty"`
}
Issuer 证书签发器配置
type Route ¶
type Route struct {
ID string `json:"@id,omitempty"`
Match []MatchHost `json:"match"`
Handle []HandleConfig `json:"handle"`
}
Route 路由配置
type ServerConfig ¶
type ServerConfig struct {
Listen []string `json:"listen"`
Routes []Route `json:"routes"`
AutoHTTPS *AutoHTTPSConfig `json:"automatic_https,omitempty"` // 自动 HTTPS 配置
}
ServerConfig 服务器配置
type TLSConfig ¶ added in v0.2.5
type TLSConfig struct {
Automation *AutomationConfig `json:"automation,omitempty"`
}
TLSConfig TLS App 配置
func GeneratePlatformTLSConfig ¶ added in v0.2.5
GeneratePlatformTLSConfig 生成平台域名的 TLS 配置 用于启动时配置 Wildcard 证书(mdfriday.com 和 *.mdfriday.com) 所有 subdomain 将自动使用此 Wildcard 证书,无需单独申请
前提条件: 1. 需要构建包含腾讯云 DNS 插件的 Caddy 实例(参见 NewDNS01Policy 注释) 2. 凭据直接在配置中传递(secretID 和 secretKey)