Architecture
+------------------------------+
client --TCP--> :443 --> | pre-filter (Tokio) | --loopback--> Pingora 127.0.0.1:4443
| conn-rate gate, abuse box, | TLS (BoringSSL), SNI certs,
| ClientHello checks, budgets | WAF, limits, routing
+------------------------------+ |
v
client --HTTP--> :80 --> ACME HTTP-01 challenges, else 301 to https upstreams / static roots
127.0.0.1:9090 /metrics, /health, /api/*
unix socket config status, verify, reload; certificate status and warmup
- The pre-filter reads the ClientHello and decides if the connection is worth it.
- Good ones get spliced to Pingora on
127.0.0.1:4443. The real client IP goes along through a table keyed by the loopback source port, so no PROXY protocol. - Pingora terminates TLS and picks the cert by SNI.
- Request checks, limits, routing, then upstream or a file from disk.
:80answers ACME challenges and redirects the rest to HTTPS.
Why the pre-filter: Pingora sets up TLS state as soon as it accepts. A flood of half-open, non-TLS or slow connections can use that up before any HTTP check runs. Reading a ClientHello first is a lot cheaper. The cost is one loopback hop and one local port per connection.
Around it: one reload task owns the config, a unix socket for control calls, the metrics listener, and a background job that renews on-demand certs.
Source
| File | |
|---|---|
main.rs | boot, runtimes, Pingora server |
tls_router.rs | the :443 pre-filter |
proxy.rs | Pingora ProxyHttp: filters, routing, upstreams |
h2_guard.rs | rapid reset guard |
limiter.rs, breaker.rs | rate limits, penalty box, breaker |
acme.rs, on_demand.rs | ACME bundle, on-demand certs |
static_handler.rs | static files |
config.rs | config and defaults |
check.rs, check_rules.rs | --check |
reload.rs | hot reload |
shield.rs, blocklist.rs | Cloudflare and crawler ranges, blocklist |
metrics.rs, control.rs, cli.rs | metrics, control socket, CLI |
tuning.rs | memory sizing |
Tests
cargo test
Unit tests for the parts (parsers, limiters, breaker, budgets, config checks, static files). No end-to-end suite, so also try changes with the local setup.