449 lines
34 KiB
Markdown
449 lines
34 KiB
Markdown
# Headless mode (no panel)
|
||
|
||
Headless mode runs RustProxy as a plain reverse proxy and load balancer configured only from a JSON file. There is no administration panel, no administration API and no administrator account. It suits small, repeatable installations: a load balancer in front of a few application replicas, a server managed with Ansible or a configuration kept in Git.
|
||
|
||
Available since 0.38.0.
|
||
|
||
## What changes compared to the panel mode
|
||
|
||
| Area | Panel mode | Headless mode |
|
||
|---|---|---|
|
||
| Configuration source | SQLite or `--config` JSON, edited in the panel | `--config` JSON only; RustProxy **never writes** the file |
|
||
| Administration listener | `--admin-listen` (default `127.0.0.1:9090`) | not opened; `--admin-listen` is ignored |
|
||
| Administrator account / setup token | required for the panel and CLI reload | not needed; no setup token is kept |
|
||
| Applying changes | panel save, `config reload` | edit the file, then `systemctl reload rustproxy` (SIGHUP) |
|
||
| Listeners | must be declared in the configuration | taken from `--proxy-listen` / `--tls-listen` when the file declares none |
|
||
| Vhost `frontend.listener_ids` | required | optional; defaults to every enabled listener |
|
||
| GeoIP downloads | on by default | off unless the file sets `geoip_updates` |
|
||
| ACME issuance and auto-renewal | panel and renewal pipeline | `headless.acme` / `--acme-domains`, `--acme-auto` (since 0.40.0); state in `<data-dir>/certs/headless-acme.json` |
|
||
| Certificate files | import in the panel | `headless.tls` / `--tls-cert-file`, `--tls-cert-dir` (since 0.40.0) |
|
||
| Configuration file | optional | required, unless `--route` is used (since 0.40.0) |
|
||
| Automatic reload on file change | — | `"watch": true` / `--watch` (since 0.40.0) |
|
||
| Forced certificate renewal | **Force renewal now** in Automatic renewal, `POST /api/acme/renew` with `force`, `rust-proxy tls renew --id ID --force` | `rust-proxy --headless tls renew [--force] [--id NAME]` (since 0.40.1) |
|
||
| Software update check | on | off |
|
||
| Health endpoint | optional `--health-listen` | optional `--health-listen` |
|
||
|
||
Everything that proxies traffic works the same: vhosts, backends and load balancing, health checks, WebSockets, HTTP/2 and HTTP/3, TLS with imported or external certificate files, cache, compression, ACLs, Basic/Forward Auth, OIDC, streams, Docker agents, Prometheus and file/Logstash logging. A SQLite database in the data directory still records each applied revision.
|
||
|
||
## The configuration file
|
||
|
||
Headless mode reads the **same configuration format** as the panel mode: every section works, including cache settings and cache rules, compression and transformations, ACL profiles and host policies, Basic Auth, Forward Auth and OIDC, web services and PHP-FPM, streams, Docker agents with their assignments, logging sinks and Prometheus. Only these fields get a default when they are missing, and only in headless mode:
|
||
|
||
| Missing field | Headless default |
|
||
|---|---|
|
||
| `listeners` (or an empty `endpoints` list) | `http` from `--proxy-listen` and `https` from `--tls-listen` |
|
||
| `frontend.listener_ids` of a vhost, redirect or 404 host | every enabled listener |
|
||
| `geoip_updates` | `{"enabled": false}` |
|
||
|
||
Anything you write explicitly is kept. One extra top-level object, `"headless"`, holds headless-only settings (certificate files, ACME, `watch`); see [HTTPS](#https-certificate-files-and-automatic-certificates). A configuration exported from the panel (about 176 KB, 31 vhosts, cache rules, Docker agents) was tested unchanged in headless mode, both on a copy of its data directory and on an empty one.
|
||
|
||
### From an existing panel installation
|
||
|
||
The panel export already is a complete headless file:
|
||
|
||
```bash
|
||
sudo -u rustproxy rust-proxy --data-dir /var/lib/rustproxy config get > config.json
|
||
```
|
||
|
||
(or **Settings → Manual config → Export JSON**). Validate it with `--headless`, install it as `/etc/rustproxy/config.json` and switch the service as shown in [Running with systemd](#running-with-systemd-debrpm-package). Certificates referenced by file name stay in `<data-dir>/certs`; keep the data directory.
|
||
|
||
### Secrets in the file
|
||
|
||
The file can contain secrets: Docker agent tokens, client secrets of login providers and Basic Auth password hashes. Keep it `0600`, owned by root or the service account, and out of public repositories. Values that support it can come from the environment instead, for example the Prometheus token (`bearer_token_env`) or the Loki token, which you set in `/etc/rustproxy/environment`.
|
||
|
||
## Minimal configuration
|
||
|
||
The smallest useful file is a single vhost ([`examples/headless-minimal.json`](../examples/headless-minimal.json)). `"*"` as the host makes it answer every hostname and IP address that no other vhost claims, so no domain is needed:
|
||
|
||
```json
|
||
{
|
||
"vhosts": [
|
||
{
|
||
"id": "app",
|
||
"websockets": true,
|
||
"frontend": { "hosts": ["*"] },
|
||
"backends": [
|
||
{ "id": "app-1", "url": "http://127.0.0.1:3101", "allow_private": true },
|
||
{ "id": "app-2", "url": "http://127.0.0.1:3102", "allow_private": true },
|
||
{ "id": "app-3", "url": "http://127.0.0.1:3103", "allow_private": true }
|
||
],
|
||
"load_balancing": {
|
||
"algorithm": "round_robin",
|
||
"health_check": { "mode": "http", "path": "/health", "interval_ms": 5000, "timeout_ms": 2000, "fall": 2, "rise": 1 }
|
||
},
|
||
"cache": { "enabled": true }
|
||
}
|
||
],
|
||
"cache": { "enabled": true, "max_bytes": 268435456 }
|
||
}
|
||
```
|
||
|
||
- Up to 32 backends per vhost. `allow_private` is required for loopback and private addresses.
|
||
- `algorithm`: `round_robin`, `least_connections` (default), `least_traffic`, `adaptive`, `random`, `hash` (with a `hash` object: `source`, `name`, `path_depth`, `ignore_case`, `balance_factor`, `fallback`) or `ip_hash`; `sticky` sessions are configured as in [Vhosts](VHOSTS.md). Routes can set `backend_ids` and their own `load_balancing`; see [Load balancing](LOAD_BALANCING.md).
|
||
- By default requests with cookies or `Authorization` and responses with `Set-Cookie` are not cached, so enabling the cache for an application with logins only stores public responses and static files.
|
||
- With an HTTPS listener and the `*` host, clients that use an IP address or an unknown name receive the default certificate (self-signed unless `tls.default_certificate` points to your own).
|
||
|
||
## Production example
|
||
|
||
[`examples/headless-production.json`](../examples/headless-production.json) is a complete load balancer for one application with a domain, ten backends, HTTPS, a two-tier cache and monitoring. It was validated with `config validate --headless` and run against ten test backends: HTTP and `www` redirect to `https://app.example.com` (308), static files are `MISS` then `HIT` with a 30-day `Cache-Control`, tracking parameters do not split the cache, `/api` is `BYPASS`, `/admin` answers `403` outside the allowed networks, `X-Powered-By` is removed, HSTS is sent, the access log is written and `/metrics` answers with the token.
|
||
|
||
What each part does:
|
||
|
||
| Part | Setting | Purpose |
|
||
|---|---|---|
|
||
| Listeners | `http` on `0.0.0.0:80`, `https` on `0.0.0.0:443` with HTTP/2 and HTTP/3 | Explicit, so the file documents the bindings. They must match `--proxy-listen` / `--tls-listen` of the service. |
|
||
| TLS | `tls.certificates` with `cert_file` / `key_file`, `default_certificate` | Files in `<data-dir>/certs`, or absolute paths to a Certbot lineage (see below). |
|
||
| Vhost | `force_ssl`, `www_redirect` + `www_redirect_target`, `websockets`, `forward_client_ip` | One canonical HTTPS address; WebSockets proxied; client IP forwarded in `X-Forwarded-For`. |
|
||
| Backends | 10 × `http://10.0.0.x:3001`, `protocol: http1` | One entry per replica. |
|
||
| Balancing | `least_connections`, active HTTP check every 5 s, `passive_health`, `retry` once on connect errors / 502 / 503 | A replica that fails two checks or keeps failing real requests is taken out; it returns after one good check. |
|
||
| Keep-alive | `idle_timeout_seconds: 60`, `max_idle_per_host: 32` | Reuses backend connections instead of opening one per request. |
|
||
| Timeouts | connect 3 s, headers 120 s, read/send 300 s | Raise read/send for large downloads, uploads or long polling. |
|
||
| Security | HSTS, `nosniff`, `frame_options`, `referrer_policy`, `rate_limit` 600/min with burst 120 | Per client IP. |
|
||
| Routes | `/admin` with an ACL (private networks only) and no cache, `/api` without cache | Location rules are checked before the vhost defaults. |
|
||
| Compression | gzip, Brotli, zstd from 1 KiB | Applied to compressible responses according to the client's `Accept-Encoding`. |
|
||
| Logs | JSON access log in `/var/log/rustproxy/access.jsonl` | Rotation as described in [Logs](LOGS.md); warnings and errors also go to the journal. |
|
||
| Prometheus | `127.0.0.1:9191/metrics`, CIDR list and `bearer_token_env: RUSTPROXY_METRICS_TOKEN` | Put `RUSTPROXY_METRICS_TOKEN=<32+ characters>` in `/etc/rustproxy/environment`. |
|
||
|
||
### Production cache
|
||
|
||
The cache is controlled globally (`cache`) and enabled per vhost (`vhosts[].cache.enabled`) and per route (`routes[].cache`). The example uses:
|
||
|
||
| Setting | Value | Meaning |
|
||
|---|---|---|
|
||
| `max_bytes` | 512 MiB | HOT tier in RAM. Process memory is always larger than this (connections, TLS, allocator); see [Performance: where the memory goes](PERFORMANCE.md#where-the-memory-goes). |
|
||
| `max_object_bytes` | 16 MiB | Larger responses are streamed and not stored. |
|
||
| `max_entries` | 16384 | Upper limit of objects (1..16384). |
|
||
| `cold_enabled`, `cold_path`, `cold_max_bytes` | on, `cache/cold` (inside the data directory), 10 GiB | COLD tier on disk: objects leave RAM after inactivity or under pressure and are read back on the next hit. Survives restarts. |
|
||
| `default_ttl_seconds` | 0 | Only responses that the backend marks cacheable (`Cache-Control`, `Expires`) are stored, unless a rule sets a TTL. |
|
||
| `max_ttl_seconds` | 86400 | Caps any TTL, also from rules. |
|
||
| `varnish_grace_seconds` | 60 | A just-expired object is served while it is refreshed in the background. |
|
||
| `bypass_prefixes` | `/api`, `/admin`, `/login` | Never cached, regardless of headers. A prefix matches the path itself and everything below it (`/api` covers `/api` and `/api/…`, not `/apix`). |
|
||
| `static_ignore_cookies` | true | Static extensions (`static_extensions`) are cached even when the browser sends cookies. Turn off if your static files depend on the session. |
|
||
| `collapse_enabled` | true | Concurrent misses for the same URL wait for one backend request. |
|
||
| `stale_if_error_*` | timeouts, connection errors, 500/502/503/504 | Serve the last good copy when the backend fails. |
|
||
| `expose_status` | true | `X-Cache` / `X-Cache-Reason` in responses; switch off once tuned. |
|
||
|
||
Cache rules in the example (same format as **Settings → Cache rules** in the panel, see [Cache](CACHE.md)):
|
||
|
||
1. **Request:** `strip_query` removes `utm_*`, `fbclid`, `gclid`, `msclkid`, `_ga`, so marketing links share one cached object.
|
||
2. **Response:** static extensions get a 30-day TTL even when the backend sends no caching headers.
|
||
3. **Deliver:** `default_header` adds `Cache-Control: public, max-age=2592000` for browsers when the backend sent none.
|
||
4. **Deliver:** `remove_header` drops `X-Powered-By`.
|
||
|
||
Check the result with `curl -sI https://app.example.com/static/app.css` (look at `X-Cache`, `Age`) and the `rust_proxy_cache_*` metrics. Without the panel there is no cache page or invalidation API; to remove objects, enable HTTP `PURGE`/`BAN` for trusted addresses with `"http_invalidation_allowed_cidrs": ["10.0.0.0/8"]` in `cache` (see [Cache](CACHE.md)), for example `curl -X PURGE https://app.example.com/static/app.css` from a deploy script. On a clean stop HOT objects are moved to the COLD tier (`cold_on_shutdown`), so the cache survives restarts.
|
||
|
||
### HTTPS with Certbot
|
||
|
||
Point the certificate at the lineage and reload RustProxy after each renewal:
|
||
|
||
```json
|
||
"tls": {
|
||
"default_certificate": "app",
|
||
"certificates": [
|
||
{ "id": "app", "hosts": ["app.example.com", "www.app.example.com"],
|
||
"cert_file": "/etc/letsencrypt/live/app.example.com/fullchain.pem",
|
||
"key_file": "/etc/letsencrypt/live/app.example.com/privkey.pem" }
|
||
]
|
||
}
|
||
```
|
||
|
||
```bash
|
||
# /etc/letsencrypt/renewal-hooks/deploy/rustproxy
|
||
#!/bin/sh
|
||
systemctl reload rustproxy
|
||
```
|
||
|
||
The service account needs read access to the files and the directories must pass the trusted-path checks; see [Certificates: existing local files](CERTIFICATES.md) and [Installation: external paths](INSTALL.md#linux-debrpm-read-only-access-to-external-paths). Since 0.40.0 the same is simpler with `--tls-cert-dir /etc/letsencrypt/live` (no JSON entry per domain) or without external Certbot at all with `--acme-domains`; see [HTTPS: certificate files and automatic certificates](#https-certificate-files-and-automatic-certificates). Certbot's DNS-01 plugins work without touching RustProxy. HTTP-01 needs `/.well-known/acme-challenge/` on port 80 to reach Certbot, for example a route with a Web Service that serves the Certbot webroot.
|
||
|
||
## HTTPS: certificate files and automatic certificates
|
||
|
||
Since 0.40.0 HTTPS can be set up without `tls.certificates` entries: certificate files, whole certificate directories and automatic DV certificates from Let's Encrypt (ACME). Every setting can be written **in the JSON file** (a top-level `"headless"` object) **or** given **on the command line / in `/etc/rustproxy/environment`**; both are merged on every start and reload. RustProxy still never writes the file.
|
||
|
||
Host names come from the certificate's subject alternative names (SAN): a vhost whose host the certificate covers serves it automatically, without `certificate_id`. An explicit binding (`hosts` of a certificate or a vhost `certificate_id`) still takes precedence. Clients that send no SNI, or a name no certificate covers, get `tls.default_certificate` (self-signed unless set). All of this needs an HTTPS listener (`--tls-listen 0.0.0.0:443` or an `https` listener in the file); a warning is logged when there is none.
|
||
|
||
### The `"headless"` section
|
||
|
||
The section is read only in headless mode and removed before the rest of the file is read, so the remaining file keeps the normal configuration format (the panel refuses a file that still contains it). Relative paths are relative to the configuration file.
|
||
|
||
```json
|
||
{
|
||
"headless": {
|
||
"watch": true,
|
||
"tls": {
|
||
"certificates": [
|
||
{ "cert_file": "/etc/ssl/app/fullchain.pem", "key_file": "/etc/ssl/app/privkey.pem" }
|
||
],
|
||
"directories": ["/etc/letsencrypt/live"]
|
||
},
|
||
"acme": {
|
||
"email": "ops@example.com",
|
||
"agree_tos": true,
|
||
"staging": false,
|
||
"provider": "http01",
|
||
"dns_credentials": "/etc/rustproxy/cloudflare.ini",
|
||
"propagation_seconds": 60,
|
||
"renew_days": 30,
|
||
"auto": true,
|
||
"domains": [
|
||
["app.example.com", "www.app.example.com"],
|
||
"api.example.com"
|
||
]
|
||
}
|
||
},
|
||
"vhosts": [ ... ]
|
||
}
|
||
```
|
||
|
||
| JSON (`headless.…`) | Command line | Environment | Meaning |
|
||
|---|---|---|---|
|
||
| `tls.certificates[].cert_file` / `key_file` | `--tls-cert-file` / `--tls-key-file` | `RUST_PROXY_TLS_CERT_FILE` / `RUST_PROXY_TLS_KEY_FILE` | Certificate chain (leaf first) and its private key. Repeatable; on the command line paired by position, comma-separated in the environment. |
|
||
| `tls.directories[]` | `--tls-cert-dir` | `RUST_PROXY_TLS_CERT_DIR` | Directory scanned on every start and reload (layouts below). |
|
||
| `acme.domains[]` | `--acme-domains` | `RUST_PROXY_ACME_DOMAINS` | Names of one certificate: a JSON list or a comma-separated string. Repeat for more certificates; in the environment separate certificates with `;`. Up to 32 certificates with 16 names each. |
|
||
| `acme.auto` | `--acme-auto` | `RUST_PROXY_ACME_AUTO=1` | Also request a certificate for every vhost/redirect host that no other certificate covers ([below](#automatic-certificates-for-every-vhost-acmeauto)). |
|
||
| `acme.email` | `--acme-email` | `RUST_PROXY_ACME_EMAIL` | ACME account contact (required). |
|
||
| `acme.agree_tos` | `--acme-agree-tos` | `RUST_PROXY_ACME_AGREE_TOS=1` | Accept the Let's Encrypt Subscriber Agreement (required). |
|
||
| `acme.staging` | `--acme-staging` | `RUST_PROXY_ACME_STAGING=1` | Let's Encrypt staging CA (untrusted test certificates). Default: production. |
|
||
| `acme.provider` | `--acme-provider` | `RUST_PROXY_ACME_PROVIDER` | `http01` (default), or DNS-01 with `cloudflare`, `ovh`, `rfc2136`. Wildcards need DNS-01. |
|
||
| `acme.dns_credentials` | `--acme-dns-credentials` | `RUST_PROXY_ACME_DNS_CREDENTIALS` | Certbot plugin credentials file for DNS-01, mode `0600`. |
|
||
| `acme.propagation_seconds` | `--acme-propagation-seconds` | `RUST_PROXY_ACME_PROPAGATION_SECONDS` | DNS-01 propagation wait, 10..900 (default 60). |
|
||
| `acme.renew_days` | `--acme-renew-days` | `RUST_PROXY_ACME_RENEW_DAYS` | Renew when this many days or fewer remain, 1..60 (default 30). |
|
||
| `watch` | `--watch` | `RUST_PROXY_WATCH=1` | Reload automatically when the file or certificate files change ([below](#automatic-reload---watch)). |
|
||
|
||
Merging: lists (certificates, directories, ACME domains) from both places are joined; for single values (e-mail, provider, …) the command line wins; switches (`agree_tos`, `staging`, `auto`, `watch`) are on when either place turns them on. ACME settings are checked when the configuration is loaded, so they may be split between the two (for example the e-mail in the environment, the domains in the file). Changing the `"headless"` section takes effect with the next reload, except `watch`, which is read at start. `config validate` accepts the same command-line options and reports what was found.
|
||
|
||
Ready-made files: [`examples/headless-https-files.json`](../examples/headless-https-files.json) (certificate files and a Certbot directory), [`examples/headless-acme.json`](../examples/headless-acme.json) (ACME with `auto` and two vhosts), [`examples/headless-acme-wildcard-dns.json`](../examples/headless-acme-wildcard-dns.json) (wildcard through Cloudflare DNS-01) and [`examples/headless.environment`](../examples/headless.environment) (the same through `/etc/rustproxy/environment`).
|
||
|
||
### Existing certificate files
|
||
|
||
JSON:
|
||
|
||
```json
|
||
"headless": { "tls": { "certificates": [ { "cert_file": "/etc/ssl/app/fullchain.pem", "key_file": "/etc/ssl/app/privkey.pem" } ] } }
|
||
```
|
||
|
||
Command line:
|
||
|
||
```bash
|
||
rust-proxy --headless --config /etc/rustproxy/config.json --data-dir /var/lib/rustproxy \
|
||
serve --proxy-listen 0.0.0.0:80 --tls-listen 0.0.0.0:443 \
|
||
--tls-cert-file /etc/ssl/app/fullchain.pem --tls-key-file /etc/ssl/app/privkey.pem
|
||
```
|
||
|
||
Directories (`tls.directories` / `--tls-cert-dir`) recognize these layouts (other files are ignored):
|
||
|
||
| Layout | Example |
|
||
|---|---|
|
||
| The directory is one lineage | `DIR/fullchain.pem` + `DIR/privkey.pem` |
|
||
| Certbot | `/etc/letsencrypt/live/<name>/fullchain.pem` + `privkey.pem` (symbolic links into `archive/` are followed) |
|
||
| acme.sh | `DIR/<name>/fullchain.cer` + `DIR/<name>/<name>.key` |
|
||
| Flat files | `DIR/<name>.crt` (or `.pem`, `.cer`) + `DIR/<name>.key` |
|
||
|
||
A directory is read again on each reload, so a Certbot deploy hook only has to run `systemctl reload rustproxy` (or nothing at all with `watch`). A new lineage added to the directory is picked up by the same reload. The files must be readable by the service account and pass the trusted-path checks described in [Certificates](CERTIFICATES.md) (for Certbot: give the `rustproxy` group read access to `live/` and `archive/`).
|
||
|
||
Each file certificate gets a stable id (`hl-file-<name>-<hash of the path>`); certificates issued by ACME get `hl-acme-<first name>-<hash of the names>`. The ids may be used elsewhere in the file, for example as `tls.default_certificate`, as long as the source that provides them stays configured.
|
||
|
||
### Automatic DV certificates (ACME)
|
||
|
||
JSON ([`examples/headless-acme.json`](../examples/headless-acme.json)):
|
||
|
||
```json
|
||
"headless": {
|
||
"acme": {
|
||
"email": "ops@example.com",
|
||
"agree_tos": true,
|
||
"domains": [["app.example.com", "www.app.example.com"], ["api.example.com"]]
|
||
}
|
||
}
|
||
```
|
||
|
||
Command line:
|
||
|
||
```bash
|
||
rust-proxy --headless --config /etc/rustproxy/config.json --data-dir /var/lib/rustproxy \
|
||
serve --proxy-listen 0.0.0.0:80 --tls-listen 0.0.0.0:443 \
|
||
--acme-domains app.example.com,www.app.example.com \
|
||
--acme-domains api.example.com \
|
||
--acme-email ops@example.com --acme-agree-tos
|
||
```
|
||
|
||
or with the packaged service:
|
||
|
||
```bash
|
||
cat <<'ENV' | sudo tee -a /etc/rustproxy/environment
|
||
RUST_PROXY_ACME_DOMAINS=app.example.com,www.app.example.com;api.example.com
|
||
RUST_PROXY_ACME_EMAIL=ops@example.com
|
||
RUST_PROXY_ACME_AGREE_TOS=1
|
||
ENV
|
||
sudo systemctl restart rustproxy
|
||
```
|
||
|
||
How it works:
|
||
|
||
- A few seconds after start RustProxy requests every certificate that is missing, was requested with different names, provider or environment, or expires within `renew_days`. It checks again every 12 hours and after every reload. Certificates are requested one at a time.
|
||
- Issuance uses the same Certbot worker as the panel ([Certificates](CERTIFICATES.md)): a managed Python environment in `<data-dir>/acme-python` is prepared on the first request (Python 3 with `venv`/`pip` and access to PyPI, or a system `certbot` as a fallback). Account keys, Certbot lineages and logs are kept per certificate in `<data-dir>/certs/acme/`.
|
||
- **HTTP-01** (default): the CA must reach `http://<name>/.well-known/acme-challenge/` on port 80 of this server, so RustProxy needs a plain HTTP listener on port 80 (directly or through port forwarding). Challenges are answered before vhost routing, also for vhosts with `force_ssl`, and only for names of the request in progress. Wildcards are not possible with HTTP-01.
|
||
- **DNS-01** (`cloudflare`, `ovh`, `rfc2136`): needed for wildcards (`*.example.com`) and for servers not reachable from the Internet ([`examples/headless-acme-wildcard-dns.json`](../examples/headless-acme-wildcard-dns.json)). `dns_credentials` points to the INI file of the Certbot plugin, mode `0600`; it is read for each request, so rotated credentials need no restart:
|
||
|
||
```ini
|
||
# cloudflare
|
||
dns_cloudflare_api_token = <token with Zone:DNS:Edit>
|
||
# ovh
|
||
dns_ovh_endpoint = ovh-eu
|
||
dns_ovh_application_key = ...
|
||
dns_ovh_application_secret = ...
|
||
dns_ovh_consumer_key = ...
|
||
# rfc2136
|
||
dns_rfc2136_server = 192.0.2.53
|
||
dns_rfc2136_port = 53
|
||
dns_rfc2136_name = keyname.
|
||
dns_rfc2136_secret = <base64>
|
||
dns_rfc2136_algorithm = HMAC-SHA256
|
||
```
|
||
|
||
- A new certificate is written to `<data-dir>/certs/acme-*.pem|key`, recorded in `<data-dir>/certs/headless-acme.json` and activated by an internal reload: running connections and the cache are kept. The previous generation is deleted afterwards.
|
||
- A failed request is logged with the path of the Certbot log and retried after 10 minutes, 30 minutes, 1, 3, 6 and then every 12 hours; Let's Encrypt limits failed validations, so test new setups with `staging` first. If the configuration file is invalid at that moment, the certificate is kept and applied by the next successful reload.
|
||
- Removing a name from `domains` changes the certificate id; the old entry in `headless-acme.json` is simply no longer used.
|
||
|
||
### Forcing a new certificate (`tls renew --force`)
|
||
|
||
Since 0.40.1 the running service can be asked to request a certificate **now**, even if it is not due yet — for example after a key compromise, after switching from `staging` to production, or after a CA revocation:
|
||
|
||
```bash
|
||
# re-issue every headless ACME certificate (explicit and acme.auto)
|
||
sudo rust-proxy --headless --data-dir /var/lib/rustproxy tls renew --force
|
||
# only the certificate containing this name (or with this hl-acme-… id); --id may be repeated or comma-separated
|
||
sudo rust-proxy --headless --data-dir /var/lib/rustproxy tls renew --force --id api.example.com
|
||
# without --force: check now and renew only what is due, also skipping the failure back-off
|
||
sudo rust-proxy --headless --data-dir /var/lib/rustproxy tls renew
|
||
```
|
||
|
||
- The command writes a short request to `<data-dir>/headless-acme-renew.json` (mode `0600`, owned by the owner of the data directory) and sends `SIGUSR1` to the process in `<data-dir>/rustproxy.pid`. The ACME task picks it up as soon as the request in progress (if any) finishes; it is processed once and deleted. Requests older than 10 minutes are discarded, so a request left behind while the service was stopped never forces a renewal after a restart.
|
||
- A forced request skips the expiry check and the failure back-off; the new certificate is installed exactly like a renewal (internal reload, connections and cache kept, the previous generation deleted). If it fails, the old certificate stays active and normal retries follow.
|
||
- Targets that match no ACME certificate are logged as warnings. Progress and results are in the service log and in [`/certificates`](#certificate-status-certificates).
|
||
- Every forced certificate counts against the CA rate limits (Let's Encrypt: 5 certificates for the same set of names per week); use `staging` to test.
|
||
- `--dry-run` is panel-only; in headless mode test with `staging`. A service older than 0.40.1 does not handle `SIGUSR1`, so on Linux the command checks this first and refuses instead of stopping it.
|
||
|
||
### Automatic certificates for every vhost (`acme.auto`)
|
||
|
||
Like a Traefik certificate resolver attached to every router: with `"auto": true` (or `--acme-auto`) RustProxy collects the hosts of all enabled vhosts and redirects, leaves out those already covered by another certificate (from `tls.certificates`, certificate files/directories or `acme.domains`, wildcards included), and requests **one certificate per vhost** for the rest (up to 16 names each, at most 64 automatic certificates). Skipped automatically: `*`, IP addresses, single-label names and, with HTTP-01, wildcard hosts (they are requested with a DNS-01 provider).
|
||
|
||
Adding a vhost or a host and reloading (or saving with `watch`) is enough to get its certificate. When the hosts of a vhost change, a new certificate is requested first; the old automatic certificate is deleted only after its served names have a replacement, and certificates whose hosts are gone are deleted. `auto` needs `email` and `agree_tos` like any ACME request; `domains` may stay empty.
|
||
|
||
```json
|
||
{
|
||
"headless": { "watch": true, "acme": { "email": "ops@example.com", "agree_tos": true, "auto": true } },
|
||
"vhosts": [
|
||
{ "id": "app", "force_ssl": true, "frontend": { "hosts": ["app.example.com", "www.app.example.com"] },
|
||
"backends": [ { "id": "a", "url": "http://127.0.0.1:3000", "allow_private": true } ] }
|
||
]
|
||
}
|
||
```
|
||
|
||
Only names that resolve to this server can pass HTTP-01; failures are retried with the back-off above and visible in [`/certificates`](#certificate-status-certificates).
|
||
|
||
### Quick start without a configuration file (`--route`)
|
||
|
||
Like Traefik's command-line routers, a vhost can be described in one option, `HOSTS=URLS`, with no `--config` at all:
|
||
|
||
```bash
|
||
rust-proxy --headless --data-dir /var/lib/rustproxy serve \
|
||
--proxy-listen 0.0.0.0:80 --tls-listen 0.0.0.0:443 \
|
||
--route app.example.com,www.app.example.com=http://127.0.0.1:3000,http://127.0.0.1:3001 \
|
||
--route api.example.com=http://127.0.0.1:8080 \
|
||
--force-https --acme-auto --acme-email ops@example.com --acme-agree-tos
|
||
```
|
||
|
||
- Each `--route` (environment `RUST_PROXY_ROUTES`, routes separated by `;`) becomes a vhost with WebSockets and `X-Forwarded-For`, balanced over the listed backends (up to 32) with the same defaults as a vhost in the file (default algorithm, TCP health checks every 5 s, so a backend takes traffic a few seconds after start once it passes them); retries, HTTP health checks and other balancing options are set in a file vhost. Private and loopback backends are allowed because the operator listed them. `*` as the host answers every name no other vhost claims.
|
||
- `--force-https` (`RUST_PROXY_FORCE_HTTPS=1`) redirects plain HTTP to HTTPS (308) for these vhosts; ACME HTTP-01 challenges are still answered.
|
||
- Routes can be combined with `--config`: they are added to the file's vhosts (a vhost id that already exists in the file is an error). Anything beyond this — cache, ACL, authentication, routes per path — belongs in the file.
|
||
- `systemctl reload` / `SIGHUP` works without a file too; it re-reads certificate files and the ACME state.
|
||
|
||
### Automatic reload (`--watch`)
|
||
|
||
Like Traefik's file provider with `watch`: with `"watch": true` (or `--watch`, `RUST_PROXY_WATCH=1`) RustProxy checks every 2 seconds the configuration file, the configured certificate files and the contents of certificate directories (following Certbot's symbolic links). A change is applied once the files have stayed unchanged for one more check, so half-written files are not loaded. The reload is the same as `systemctl reload`: an invalid file is rejected and logged and the running configuration stays active. Write the file atomically (write a temporary file and rename it) when a tool generates it. Listener changes still need a restart.
|
||
|
||
### Certificate status (`/certificates`)
|
||
|
||
With `--health-listen`, `GET /certificates` returns every active certificate — id, source (`configuration`, `file`, `acme`, `acme-auto`), default flag, bound hosts, names from the certificate, issuer, `not_after`, `days_remaining`, `expiry_status` — and the state of each headless ACME request (`valid`, `issuing`, `waiting`, `failed` with the last error, failures and next check). It contains only public certificate data; keep the listener on loopback or a private network like `/healthz`.
|
||
|
||
```bash
|
||
curl -s http://127.0.0.1:9091/certificates | jq '.certificates[] | {id, source, covered_hosts, days_remaining}'
|
||
```
|
||
|
||
## Coming from Traefik or Envoy
|
||
|
||
| Traefik / Envoy | RustProxy headless |
|
||
|---|---|
|
||
| File provider, `watch: true` | `--config` JSON file, `"watch": true` / `--watch` |
|
||
| CLI/labels routers (`Host(...)` → service) | `--route HOSTS=URLS`, or vhosts in the file; Docker labels through the [Docker agent](DOCKER_DISCOVERY.md) |
|
||
| `certResolver` with HTTP or DNS challenge | `acme.domains`, `acme.auto`, `provider` `http01`/`cloudflare`/`ovh`/`rfc2136` |
|
||
| Default certificate / TLS store | `tls.default_certificate`, `tls.certificates`, `headless.tls` |
|
||
| Entry point redirect to HTTPS | vhost `force_ssl`, `--force-https` for `--route` |
|
||
| Weighted round robin, backup servers | `load_balancing.algorithm`, backend `weight`, `backup`, `drain` |
|
||
| Health checks / outlier detection | `health_check` (active), `passive_health` (ejection after real failures), `slow_start_seconds` |
|
||
| Retry policy | `retry` (`max_retries`, connect errors, timeouts, statuses) |
|
||
| Circuit breakers (`max_requests`, `max_pending_requests`) | backend `max_concurrent_requests` + `queue_timeout_ms`, vhost `rate_limit` |
|
||
| Sticky sessions / hash policy | `sticky`, `ip_hash`, `hash` (consistent: path, header, cookie, query, IP; `balance_factor` for bounded load) |
|
||
| Admin `/ready`, `/clusters`, `/certs` | `/healthz` (pools), `/certificates` on `--health-listen`; Prometheus `/metrics` |
|
||
| Hot restart | `SIGHUP` reload without dropping connections; listener changes need a restart |
|
||
|
||
## Validate before starting
|
||
|
||
```bash
|
||
rust-proxy --headless --data-dir /var/lib/rustproxy config validate /etc/rustproxy/config.json
|
||
```
|
||
|
||
The check applies the same defaults as the running service and compiles the configuration without touching the data directory. Set `RUST_PROXY_PROXY_LISTEN` / `RUST_PROXY_TLS_LISTEN` to the service addresses when they differ from the defaults, so listener conflicts are checked against the real bindings.
|
||
|
||
## Running with systemd (DEB/RPM package)
|
||
|
||
The packaged unit already reads `/etc/rustproxy/environment`, so headless mode needs no unit edit:
|
||
|
||
```bash
|
||
sudo install -d -m 0700 /etc/rustproxy
|
||
sudo install -o rustproxy -g rustproxy -m 0600 config.json /etc/rustproxy/config.json
|
||
printf 'RUST_PROXY_HEADLESS=1\nRUST_PROXY_CONFIG=/etc/rustproxy/config.json\n' | sudo tee -a /etc/rustproxy/environment
|
||
sudo systemctl restart rustproxy
|
||
sudo journalctl -u rustproxy -n 30 --no-pager
|
||
```
|
||
|
||
Optional health endpoint for an external balancer or keepalived: add `RUST_PROXY_HEALTH_LISTEN=127.0.0.1:9091` to the same file.
|
||
|
||
After editing the configuration:
|
||
|
||
```bash
|
||
rust-proxy --headless --data-dir /var/lib/rustproxy config validate /etc/rustproxy/config.json
|
||
sudo systemctl reload rustproxy
|
||
```
|
||
|
||
`systemctl reload` runs `rust-proxy reload`, which in headless mode sends `SIGHUP` to the service (the process id is kept in `<data-dir>/rustproxy.pid`). `kill -HUP <pid>` does the same. A valid file is applied without dropping connections or the cache; an invalid one is rejected, logged, and the running configuration stays active. Listener address or protocol changes still need a restart.
|
||
|
||
## Running directly or in a container
|
||
|
||
```bash
|
||
rust-proxy --headless --config /etc/rustproxy/config.json --data-dir /var/lib/rustproxy \
|
||
serve --proxy-listen 0.0.0.0:80 --tls-listen 0.0.0.0:443 --health-listen 127.0.0.1:9091
|
||
```
|
||
|
||
In a container, mount the file read-only (RustProxy never writes it) and keep `/var/lib/rustproxy` on a volume for certificates, secrets and the optional COLD cache. Backends in the same Compose network can be addressed by service name, for example `http://app-1:3001`. Give each replica its own service and backend entry: one name that resolves to several container addresses is treated as a single backend.
|
||
|
||
## Health endpoint
|
||
|
||
`GET /healthz` on `--health-listen` answers `200` while every vhost with backends has at least one healthy backend and `503` otherwise:
|
||
|
||
```json
|
||
{"status":"ok","mode":"headless","version":"0.38.7","revision":4,"uptime_seconds":120,
|
||
"last_reload":{"ok":true,"at_unix":1794743660,"error":null},
|
||
"vhosts_without_healthy_backends":[],
|
||
"pools":[{"vhost":"app","healthy":3,"backends":3}]}
|
||
```
|
||
|
||
`last_reload` reports the result of the last reload (`null` before the first one). Keep the listener on loopback or a private network. The same listener serves [`/certificates`](#certificate-status-certificates).
|
||
|
||
## Limits
|
||
|
||
- No panel, live logs (`--livelogs`), configuration history browser or cache invalidation API. Use stored log files, the journal and Prometheus instead; HTTP `PURGE`/`BAN` from allowed addresses still works for the cache.
|
||
- Certificates in the file with ACME auto-renewal (`issuer.auto_renew`) are refused; use `--acme-domains` instead, or renew externally and reference the files in `cert_file` / `key_file`. A replaced certificate file is loaded on the next reload.
|
||
- Certificates from `headless.tls`, `headless.acme`, `--tls-cert-file`, `--tls-cert-dir` or `--acme-*` and vhosts from `--route` exist only in headless mode; remove the `"headless"` section before using the file in the panel and, before switching to the panel, import them there (or reference the files in `tls.certificates`).
|
||
- To manage a headless file in the panel later, first add `listeners` and every `listener_ids` explicitly (panel mode requires them and enables GeoIP downloads by default), then restart without `RUST_PROXY_HEADLESS`, create the administrator and keep `--config`: panel saves then write the complete configuration to the file.
|