Caddy
Caddy in the App
An app on Octane with FrankenPHP has Caddy built in. Behind a proxy such as Pods', an external load balancer or on Laravel Cloud, the built-in Caddy can proxy other services (Reverb, Mailpit, S3 storage) itself. You configure it through Octane's CADDY_EXTRA_CONFIG environment variable.
Foxws\Podman\Support\CaddySites builds that value from env vars. Use it in config/octane.php:
use Foxws\Podman\Support\CaddySites;
'caddy' => [
'env' => [
// Port must match the "--port" passed to "octane:frankenphp" in APP_COMMAND.
'CADDY_EXTRA_CONFIG' => CaddySites::render([
CaddySites::hostFromUrl((string) env('AWS_URL')) => CaddySites::hostPortFromUrl((string) env('AWS_ENDPOINT')),
(string) env('VITE_REVERB_HOST', env('REVERB_HOST')) => CaddySites::hostPort(env('REVERB_HOST'), env('REVERB_PORT', 6001)),
(string) env('MAILPIT_UI_HOST') => CaddySites::hostPort(env('MAIL_HOST'), 8025),
], (int) env('OCTANE_PORT', 8000)),
],
],
With AWS_URL=https://s3.laravel.test, VITE_REVERB_HOST=ws.laravel.test and MAILPIT_UI_HOST=mail.laravel.test in .env, you get:
| Hostname | Upstream | Env vars |
|---|---|---|
s3.laravel.test |
e.g. minio:9000 |
AWS_URL, AWS_ENDPOINT |
ws.laravel.test |
e.g. reverb:6001 |
VITE_REVERB_HOST (or REVERB_HOST), REVERB_HOST, REVERB_PORT |
mail.laravel.test |
e.g. mailpit:8025 |
MAILPIT_UI_HOST, MAIL_HOST |
Add or remove entries to match the services you use.
A few things to know:
- Use
env()here, notconfig(). Config files can't rely on each other's load order. - An entry with an empty hostname or upstream (unset env var) is skipped.
render()useshttp://by default. With a bare hostname, Caddy would try automatic HTTPS on port 443. An image that runs as a non-root user, as it should, without permission to bind that port, so the server would crash. Only pass the third$schemeargument if your Caddy is allowed to bind ports below 1024.
Put your TLS proxy in front of the app's port and send every hostname to it, keeping the original Host header. For example, with Caddy on the host:
laravel.test, s3.laravel.test, ws.laravel.test, mail.laravel.test {
reverse_proxy 127.0.0.1:8000 {
stream_close_delay 5m
}
}
stream_close_delay keeps WebSocket connections open for a while after a Caddy reload. Caddy passes the Host header through by default, so don't override it with header_up Host.
Paths instead of subdomains
Some services can also run under a path of the app's own domain, such as laravel.test/ws instead of ws.laravel.test. That needs no extra DNS entries or certificates, and the browser sees the same origin, so you need no CORS or CSP entries for those services. Subdomains are the default because every service supports them. Use a path only for services that work under one:
| Service | Under a path? | What it needs |
|---|---|---|
| Reverb | Yes | Strip the path. Reverb keeps serving from /, and Echo connects with wsPath |
| Mailpit | Yes | Keep the path, and set MP_WEBROOT to it on the Mailpit container |
| S3 (RustFS, MinIO) | Public URLs only | Signed URLs (temporaryUrl()) are signed over the full path, so a stripped prefix breaks them. Keep a subdomain |
| RustFS console | No | The console expects to run from / |
| Vite dev server | Not reliably | It serves its modules from /. Keep a subdomain |
CaddyRoutes renders the routes for the app's site block, which FrankenPHP takes from CADDY_SERVER_EXTRA_DIRECTIVES in config/octane.php. Services you keep on subdomains stay in CADDY_EXTRA_CONFIG:
use Foxws\Podman\Support\CaddyRoutes;
'CADDY_SERVER_EXTRA_DIRECTIVES' => CaddyRoutes::make()
// Reverb stays at "/", the browser connects to "/ws".
->route(env('VITE_REVERB_PATH'), env('REVERB_HOST'), env('REVERB_PORT', 6001))
// Mailpit serves from "/mail/" itself.
->route(env('MAILPIT_PATH'), env('MAIL_HOST'), 8025, stripPrefix: false)
->render(),
By default the path is stripped before the request reaches the service. Pass stripPrefix: false for services that serve from the path themselves. A route with an empty path, host or port is skipped, so an unset env variable turns it off. upstream() takes a ready host:port instead, and CaddySites::routes() is a shorthand for a list of routes that all strip or all keep their path. Setting CADDY_SERVER_EXTRA_DIRECTIVES replaces Octane's Mercure directives, which use the same variable.
Then point the services at the path:
-
Reverb: set
VITE_REVERB_HOSTto the app's own host and addVITE_REVERB_PATH=/ws. Pass the path to Echo aswsPath(for example throughconfig/reverb.php, next towsHost), then rebuild the frontend. Laravel keeps broadcasting straight toREVERB_HOST:REVERB_PORT, so the server side doesn't change. -
Mailpit: add
MAILPIT_PATH=/mail, and set the same path on the Mailpit container, in its Quadlet:Environment=MP_WEBROOT=/mail
Your TLS proxy in front of the app must forward WebSocket upgrades for /ws. Pods' proxy does, since it sends the app's domain to the app.
