DEV Community

konsongong
konsongong

Posted on Originally published at vpsfolio.com

Shared Caddy 2 Reverse Proxy for Multiple Self-Hosted Docker Apps

Measured Sandbox Benchmark

Idle RAM Startup Containers Recommended VPS
79.6 MB 102.6s 3 1 GB VPS

Per-container RAM: vaultwarden 46.9 MB · memos 21.7 MB · caddy 10.9 MB (sandbox verified 2026-11-24)

View the interactive benchmark plate and full VPS sizing comparison or compare all measured stacks on VPSFolio Benchmarks.


Architecture and why these pieces fit together

One public entrypoint, many private backends. Caddy 2 sits on a dedicated bridge network (proxy_net) and is the only container that publishes a host port. Vaultwarden and Memos join the same network but never expose ports: to the host, so their HTTP listeners are reachable only from Caddy. That is the whole pattern: a single TLS terminator, a shared L2 segment, and per-app Compose files that can come and go without touching the proxy.

Caddy is a good fit here because its config is small, its automatic HTTPS is real (ACME + OCSP stapling + HTTP/3), and it handles WebSocket upgrades in reverse_proxy without extra directives. Vaultwarden needs WebSockets for live sync notifications; Memos is a plain HTTP app. Both work through the same reverse_proxy block.

The sandbox-safe Compose file below uses auto_https off and binds Caddy to 127.0.0.1:18080 so you can verify routing with curl -H "Host: ..." before any DNS or certificate work. In production you flip two lines and Caddy gets real Let's Encrypt certs on 80/443.

Prerequisites, ports, and VPS sizing

  • A VPS with Docker Engine 24+ and the Compose v2 plugin (docker compose version).
  • A 1 GB RAM VPS has plenty of headroom. In our 3-container sandbox run, this stack totaled 79.6 MB idle (vaultwarden 46.9 MB with WebSockets enabled, memos 21.7 MB, caddy 10.9 MB) — compared with 7.1 MB and 18.5 MB in our standalone Vaultwarden and Memos guides. The rest of the 1 GB stays free for SQLite writes and OS page cache.
  • Ports: in the sandbox, only 127.0.0.1:18080 is published. In production, publish 80:80 and 443:443 (and 443:443/udp if you want HTTP/3).
  • DNS: two A/AAAA records pointing at the VPS, e.g. vault.example.com and memos.example.com. For local verification, add vault.local and memos.local to /etc/hosts pointing at 127.0.0.1.
  • No host bind mounts. All persistent state lives in named volumes (vw_data, memos_data, caddy_data, caddy_config). The Caddyfile is inlined via Compose top-level configs:.

Single-file Docker Compose setup

Create the project directory and write both files. The .env holds secrets; the Compose file holds everything else.

mkdir -p /opt/proxy-stack && cd /opt/proxy-stack
cat <<'EOF' > .env
# Public hostnames used by Caddy and by Vaultwarden's DOMAIN setting
VAULT_HOST=vault.local
MEMOS_HOST=memos.local

# Sandbox-safe host port for Caddy
CADDY_HTTP_PORT=18080

# Vaultwarden secrets — generate real values before production
ADMIN_TOKEN=replace-with-a-long-random-token
PUSH_INSTALLATION_KEY=replace-with-a-push-installation-key
SIGNUPS_ALLOWED=true

# Shared settings
TZ=UTC
LOG_LEVEL=info
MEMOS_TAG=stable
EOF
Enter fullscreen mode Exit fullscreen mode

Now the Compose file. Note the inline configs: block: the Caddyfile is embedded, not bind-mounted.

cat <<'EOF' > compose.yml
services:
  caddy:
    image: caddy:2-alpine
    container_name: caddy
    restart: unless-stopped
    ports:
      - "127.0.0.1:${CADDY_HTTP_PORT:-18080}:80"
    configs:
      - source: caddyfile
        target: /etc/caddy/Caddyfile
    volumes:
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - proxy_net

  vaultwarden:
    image: vaultwarden/server:latest
    container_name: vaultwarden
    restart: unless-stopped
    environment:
      DOMAIN: http://${VAULT_HOST:-vault.local}
      ADMIN_TOKEN: ${ADMIN_TOKEN}
      PUSH_INSTALLATION_KEY: ${PUSH_INSTALLATION_KEY}
      SIGNUPS_ALLOWED: ${SIGNUPS_ALLOWED:-true}
      TZ: ${TZ:-UTC}
      LOG_LEVEL: ${LOG_LEVEL:-info}
      ENABLE_WEBSOCKET: "true"
      IP_HEADER: X-Real-IP
      IP_HEADER_TRUSTED_PROXIES: local
    volumes:
      - vw_data:/data
    networks:
      - proxy_net

  memos:
    image: neosmemo/memos:${MEMOS_TAG:-stable}
    container_name: memos
    restart: unless-stopped
    environment:
      TZ: ${TZ:-UTC}
    volumes:
      - memos_data:/var/opt/memos
    networks:
      - proxy_net

networks:
  proxy_net:
    driver: bridge

volumes:
  caddy_data:
  caddy_config:
  vw_data:
  memos_data:

configs:
  caddyfile:
    content: |
      {
        auto_https off
      }

      (security_headers) {
        header {
          X-Content-Type-Options nosniff
          Referrer-Policy strict-origin-when-cross-origin
          X-Frame-Options DENY
        }
      }

      http://vault.local {
        import security_headers
        reverse_proxy vaultwarden:80
      }

      http://memos.local {
        import security_headers
        reverse_proxy memos:5230
      }
EOF
Enter fullscreen mode Exit fullscreen mode

Bring it up:

docker compose up -d
docker compose ps
Enter fullscreen mode Exit fullscreen mode

You should see three containers running. Only caddy has a published port.

Local verification before going live

Add the hostnames to /etc/hosts if you haven't already:

echo "127.0.0.1 vault.local memos.local" | sudo tee -a /etc/hosts
Enter fullscreen mode Exit fullscreen mode

Probe each backend through Caddy. The Host header is what Caddy matches on, so you don't need DNS for this step.

curl -i -H "Host: vault.local" http://127.0.0.1:18080/
curl -i -H "Host: memos.local" http://127.0.0.1:18080/
Enter fullscreen mode Exit fullscreen mode

Expect 200 OK from both. Vaultwarden returns its web vault HTML; Memos returns its SPA shell. If you get 502, Caddy is up but the backend isn't reachable on proxy_net — check docker compose logs vaultwarden and docker compose logs memos. If you get 404, the Host header didn't match a site block; confirm the Caddyfile content with docker compose exec caddy cat /etc/caddy/Caddyfile.

Confirm the backends are not reachable from the host:

curl -sS --max-time 2 http://127.0.0.1:8000/ || echo "vaultwarden not exposed (good)"
curl -sS --max-time 2 http://127.0.0.1:5230/ || echo "memos not exposed (good)"
Enter fullscreen mode Exit fullscreen mode

Both should fail to connect. That's the point of the pattern.

Production cutover (HTTPS / remote backups)

Two changes turn this into a real TLS terminator.

1. Remove auto_https off and switch to real hostnames. Edit the caddyfile config block in compose.yml:

 configs:
   caddyfile:
     content: |
-      {
-        auto_https off
-      }
-
       (security_headers) {
         header {
           X-Content-Type-Options nosniff
           Referrer-Policy strict-origin-when-cross-origin
           X-Frame-Options DENY
         }
       }

-      http://vault.local {
+      vault.example.com {
         import security_headers
         reverse_proxy vaultwarden:80
       }

-      http://memos.local {
+      memos.example.com {
         import security_headers
         reverse_proxy memos:5230
       }
Enter fullscreen mode Exit fullscreen mode

2. Publish 80 and 443. Replace the sandbox port mapping:

     ports:
-      - "127.0.0.1:${CADDY_HTTP_PORT:-18080}:80"
+      - "80:80"
+      - "443:443"
+      - "443:443/udp"
Enter fullscreen mode Exit fullscreen mode

Also update .env and switch DOMAIN in compose.yml from http://${VAULT_HOST:-vault.local} to https://${VAULT_HOST} so Vaultwarden serves HTTPS URLs (required by Bitwarden clients for WebCrypto):

sed -i 's|^VAULT_HOST=.*|VAULT_HOST=vault.example.com|' .env
sed -i 's|^MEMOS_HOST=.*|MEMOS_HOST=memos.example.com|' .env
sed -i 's|DOMAIN: http://|DOMAIN: https://|' compose.yml
Enter fullscreen mode Exit fullscreen mode

Apply with docker compose up -d. Caddy will request certificates on first request to each hostname. Watch the logs:

docker compose logs -f caddy
Enter fullscreen mode Exit fullscreen mode

You should see certificate obtained successfully for each domain. If ACME fails, the usual causes are: port 80 blocked by the provider firewall, DNS not yet propagated, or a CAA record that doesn't allow Let's Encrypt.

Splitting Caddy into its own stack. Once you have more than a couple of apps, move the proxy to /opt/proxy/compose.yml and use an external network so app stacks can join and leave without restarting Caddy:

docker network create proxy
Enter fullscreen mode Exit fullscreen mode

In /opt/proxy/compose.yml, set networks: proxy: external: true and attach Caddy to it. In each app's Compose file, declare the same external network and add it to the service. Caddy resolves backends by container name on that network, so reverse_proxy vaultwarden:80 keeps working as long as the container is named vaultwarden and joined to proxy.

Remote backups. The named volumes are the state. Back them up with a one-shot container that mounts the volumes read-only and writes a tarball to a remote target. For example, using rclone against an S3 bucket:

docker run --rm \
  -v proxy-stack_vw_data:/data/vw:ro \
  -v proxy-stack_memos_data:/data/memos:ro \
  -v proxy-stack_caddy_data:/data/caddy:ro \
  -e RCLONE_CONFIG=/tmp/rclone.conf \
  -v /root/.config/rclone/rclone.conf:/tmp/rclone.conf:ro \
  alpine sh -c 'apk add --no-cache tar gzip >/dev/null && tar czf - -C /data . | rclone rcat remote:backups/proxy-$(date +%F).tgz'
Enter fullscreen mode Exit fullscreen mode

Schedule that with cron or a systemd timer. Restore is the reverse: download the tarball, stop the stack, extract into the volumes, start again.

Day-2 operations, backups, and trade-offs

Upgrades. Caddy, Vaultwarden, and Memos all publish rolling tags. Pin versions in .env (MEMOS_TAG=0.22.0, and replace vaultwarden/server:latest with a digest) if you want reproducible deploys. Upgrade one service at a time: docker compose pull vaultwarden && docker compose up -d vaultwarden. Caddy reloads its config on SIGHUP, but docker compose restart caddy is simpler and takes under a second.

Failure modes. If Caddy is down, every app is down — that's the cost of a single entrypoint. Keep the Caddy container's restart policy at unless-stopped and monitor it. If a backend is down, Caddy returns 502 for that host only; the other sites keep serving. If proxy_net gets recreated (e.g., you delete the network), Caddy's upstream DNS cache goes stale; restart Caddy after network changes.

Backups. The critical volumes are vw_data (Vaultwarden's SQLite DB and attachments) and memos_data (Memos' SQLite DB). caddy_data holds certificates and ACME account keys; back it up too, or accept a brief re-issuance on restore. Test restores quarterly — an untested backup is a guess.

Trade-offs. A shared Caddy is simpler than per-app reverse proxies and uses less RAM, but it couples app availability to the proxy. Splitting Caddy into its own stack with an external network decouples lifecycle: you can docker compose down an app without touching the proxy. The cost is one more Compose file and a network that must exist before any stack starts. For a 1 GB VPS running two or three apps, the single-file version in this guide is the right default; split when you outgrow it.

Security headers. The security_headers snippet sets X-Content-Type-Options, Referrer-Policy, and X-Frame-Options. Vaultwarden's admin panel and web vault work fine with these. If you embed Memos in an iframe elsewhere, drop X-Frame-Options for that site block only.

WebSockets. Vaultwarden's ENABLE_WEBSOCKET=true and IP_HEADER_TRUSTED_PROXIES=local are set so it trusts Caddy's X-Real-IP and accepts upgrade requests. Caddy's reverse_proxy forwards Upgrade and Connection headers automatically; no extra config needed. If live sync doesn't work, check docker compose logs caddy | grep -i upgrade and confirm the browser is hitting the same hostname Caddy is configured for.


Measured in our sandbox run: total memory 79.6 MB (sum of per-container peaks over a 30s idle window after startup) across 3 containers; largest container 46.9 MB; published port(s) 18080; HTTP probe returned 200, 200. The run took 102.6s including the image download. Required secret(s) ADMIN_TOKEN, PUSH_INSTALLATION_KEY were generated for the test run, as the tutorial instructs. Container breakdown: vaultwarden 46.9 MB, memos 21.7 MB, caddy 10.9 MB. Verified routes: Vaultwarden via shared Caddy (HTTP 200), Memos via shared Caddy (HTTP 200).


Verification: we ran this docker-compose stack in a disposable Docker environment and recorded the measurements above. They describe that run, not a guarantee for your host.


Originally published with full interactive benchmark metrics and server sizing notes at https://vpsfolio.com/stacks/shared-caddy-reverse-proxy-multiple-docker-apps/.

Top comments (0)