v0.38.0
This commit is contained in:
1 parent
df0e39b899
commit
21aef61dd5
35 files changed
+1360
-100
No files matched your search
@@ -0,0 +1,211 @@
|
||||
# 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 | not available; use external certificate files (for example Certbot) |
|
||||
| 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. 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` or `ip_hash`; `sticky` sessions are configured as in [Vhosts](VHOSTS.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. |
|
||||
| `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). 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.
|
||||
|
||||
## 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.0","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.
|
||||
|
||||
## 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 with ACME auto-renewal are refused; renew externally and reference the files in `cert_file` / `key_file`. A replaced certificate file is loaded on the next reload.
|
||||
- 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.
|
||||
Reference in new issue
Block a user