Documentation
¶
Overview ¶
Package caddy is the web server and reverse proxy configuration tool
Index ¶
- Constants
- Variables
- func GenerateCaddyfile(appName, domain, outputMode string, port int, appDir string, ...) string
- func GlobalOptions() string
- func UpgradeGlobalOptions(content string) (string, bool)
- type CaddyManager
- func (cm *CaddyManager) ApplyConfig(ctx context.Context, config *Config) error
- func (cm *CaddyManager) GetConfig(ctx context.Context) (*Config, error)
- func (cm *CaddyManager) LoadConfig(filePath string) (*Config, error)
- func (cm *CaddyManager) PatchConfig(ctx context.Context, path string, config any) error
- func (cm *CaddyManager) SaveConfig(config *Config, filePath string) error
- func (cm *CaddyManager) ValidateConfig(ctx context.Context, config *Config) error
- type Config
Constants ¶
const GlobalOptionsMarker = "client_ip_headers CF-Connecting-IP"
GlobalOptionsMarker identifies a main Caddyfile whose global block already carries the real-client-IP settings.
Variables ¶
var CloudflareProxyRanges = []string{
"173.245.48.0/20", "103.21.244.0/22", "103.22.200.0/22", "103.31.4.0/22",
"141.101.64.0/18", "108.162.192.0/18", "190.93.240.0/20", "188.114.96.0/20",
"197.234.240.0/22", "198.41.128.0/17", "162.158.0.0/15", "104.16.0.0/13",
"104.24.0.0/14", "172.64.0.0/13", "131.0.72.0/22",
"2400:cb00::/32", "2606:4700::/32", "2803:f800::/32", "2405:b500::/32",
"2405:8100::/32", "2a06:98c0::/29", "2c0f:f248::/32",
}
CloudflareProxyRanges are Cloudflare's published edge ranges (https://www.cloudflare.com/ips/). They change rarely; when they do, update this list and re-ship — EnsureMainCaddyfile rewrites the global block.
Functions ¶
func GenerateCaddyfile ¶
func GlobalOptions ¶ added in v1.3.0
func GlobalOptions() string
GlobalOptions is the canonical global options block for /etc/caddy/Caddyfile.
trusted_proxies + client_ip_headers make Caddy resolve the REAL visitor IP when a domain is proxied through Cloudflare (orange cloud). Without them client_ip is a Cloudflare edge address: country stats are wrong and the fail2ban jail bans Cloudflare itself, locking out real users. Only requests that actually arrive from a Cloudflare range may set the header, so a direct-to-origin client cannot spoof its IP.
func UpgradeGlobalOptions ¶ added in v1.3.0
UpgradeGlobalOptions rewrites the legacy NextDeploy global block ("{\n\torder coraza_waf first\n}") to GlobalOptions(). Content that already has the marker, or a hand-edited global block it doesn't recognise, is returned unchanged with ok=false so an operator's customisation is never clobbered.
Types ¶
type CaddyManager ¶
type CaddyManager struct {
// contains filtered or unexported fields
}
func New ¶
func New(adminAPI string) *CaddyManager
func (*CaddyManager) ApplyConfig ¶
func (cm *CaddyManager) ApplyConfig(ctx context.Context, config *Config) error
func (*CaddyManager) GetConfig ¶
func (cm *CaddyManager) GetConfig(ctx context.Context) (*Config, error)
func (*CaddyManager) LoadConfig ¶
func (cm *CaddyManager) LoadConfig(filePath string) (*Config, error)
func (*CaddyManager) PatchConfig ¶
func (*CaddyManager) SaveConfig ¶
func (cm *CaddyManager) SaveConfig(config *Config, filePath string) error
func (*CaddyManager) ValidateConfig ¶
func (cm *CaddyManager) ValidateConfig(ctx context.Context, config *Config) error