proxy

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package proxy is Zelie's web front door. It terminates HTTPS, gets certificates automatically, and forwards each domain to the container that serves it. It runs as its own unprivileged process so the panel can restart or update without dropping a single site.

Index

Constants

View Source
const (
	TLSACME       = "acme"        // certificates from Let's Encrypt
	TLSSelfSigned = "self-signed" // for machines no certificate authority can reach
	// TLSTunnel is for a proxy behind a Cloudflare Tunnel: Cloudflare holds
	// the certificates, and the proxy serves plain HTTP on a loopback port
	// that only the tunnel's connector reaches.
	TLSTunnel = "tunnel"
)

TLS modes.

Variables

This section is empty.

Functions

func ValidDomain

func ValidDomain(h string) bool

ValidDomain reports whether h, in lower case, is a domain name the proxy can route.

Types

type Addrs

type Addrs struct {
	HTTP   string // e.g. ":80"
	HTTPS  string // e.g. ":443"; empty behind a tunnel
	Socket string // control socket for the panel
}

Addrs says where the proxy listens.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client changes the proxy's configuration over its control socket.

func NewClient

func NewClient(socket string) *Client

func (*Client) Apply

func (c *Client) Apply(ctx context.Context, cfg Config) error

func (*Client) Config

func (c *Client) Config(ctx context.Context) (Config, error)

func (*Client) Stats added in v0.5.0

func (c *Client) Stats(ctx context.Context) (Stats, error)

Stats returns the requests the proxy has counted for each host.

func (*Client) Version added in v0.2.0

func (c *Client) Version(ctx context.Context) (string, error)

Version asks the running proxy which version it is.

type Config

type Config struct {
	TLS    string  `json:"tls"`
	Email  string  `json:"email,omitempty"` // for the certificate authority
	Panel  string  `json:"panel,omitempty"` // host name the panel answers on
	Routes []Route `json:"routes"`
}

Config is everything the proxy serves. It is always replaced as a whole.

func (*Config) Validate

func (c *Config) Validate() error

Validate rejects anything the proxy should not serve. Upstreams must be container addresses: apart from the panel's own socket, the proxy is never a way to reach the host or the wider network.

type Counts added in v0.5.0

type Counts struct {
	Requests uint64 `json:"requests"`
	// ClientErrors are 4xx answers; ServerErrors are 5xx, including the
	// 502 the proxy gives when the app does not answer.
	ClientErrors uint64 `json:"client_errors"`
	ServerErrors uint64 `json:"server_errors"`
}

Counts are the requests one host has had since the proxy started.

type Proxy

type Proxy struct {
	StateDir    string
	PanelSocket string // Unix socket the panel listens on
	Log         *slog.Logger
	// contains filtered or unexported fields
}

Proxy serves the configured routes. Apply swaps in a new configuration without dropping open connections.

func (*Proxy) Apply

func (p *Proxy) Apply(ctx context.Context, cfg Config) error

Apply validates cfg, saves it and starts serving it.

func (*Proxy) Config

func (p *Proxy) Config() Config

func (*Proxy) Load

func (p *Proxy) Load(ctx context.Context) error

Load applies the configuration saved by the last Apply, so the proxy can start serving on its own after a reboot, before the panel is up.

func (*Proxy) Serve

func (p *Proxy) Serve(ctx context.Context, a Addrs, allowed peer.Policy) error

Serve loads the saved configuration and serves until ctx is done. On shutdown open requests get up to half a minute to finish.

func (*Proxy) Stats added in v0.5.0

func (p *Proxy) Stats() Stats

Stats returns the requests counted for each host.

type Route

type Route struct {
	Host     string `json:"host"`
	Upstream string `json:"upstream"`
}

Route sends requests for Host to Upstream, a container address.

type Stats added in v0.5.0

type Stats struct {
	Since time.Time         `json:"since"`
	Hosts map[string]Counts `json:"hosts"`
}

Stats is what the proxy has counted. Since changes when the proxy restarts and the counts start again from zero.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL