Skip to content
Vaulthalla LogoVaulthalla

Serve Vaulthalla With nginx

Use vh setup nginx on Linux to put the console behind nginx, with Let's Encrypt over HTTP-01 or Cloudflare DNS-01 and an optional S3 hostname.

On Linux, the Debian package integrates with the distribution's nginx. sudo vh setup nginx writes a Vaulthalla-managed site from the runtime configuration, validates it with nginx -t, reloads nginx conservatively, and checks that the console answers. With a certificate option it also obtains and renews a Let's Encrypt certificate.

Modes

1sudo vh setup nginx                                   # HTTPS with the local certificate, catch-all server name2sudo vh setup nginx --domain vault.example.com        # HTTPS with the local certificate, one name3sudo vh setup nginx --plain-http                      # HTTP only, behind another TLS terminator4sudo vh setup nginx --domain vault.example.com --certbot5sudo vh setup nginx --domain vault.example.com --s3-domain s3.vault.example.com \6  --certbot-dns-cloudflare /etc/vaulthalla/certbot/cloudflare.ini
Mode Certificate Requirements
No certificate option The host's local certificate (self-signed), /etc/vaulthalla/tls/local.crt None. Browsers ask you to trust the certificate once; compare the SHA-256 fingerprint vh setup nginx prints.
--plain-http None Only behind another TLS terminator (a tunnel or load balancer that already serves HTTPS).
--certbot Let's Encrypt, HTTP-01, through Certbot's nginx plugin The domain resolves to the host and port 80 reaches it from the internet.
--certbot-dns-cloudflare <credentials> Let's Encrypt, DNS-01 through Cloudflare DNS on Cloudflare and a scoped API token; no inbound ports needed. The only mode that supports --s3-domain.

Every mode except --plain-http redirects http:// to https:// and sends security headers (X-Content-Type-Options, Referrer-Policy: no-referrer, X-Frame-Options: DENY, frame-ancestors 'none'). With a Let's Encrypt certificate it also sends HSTS; with the local certificate it doesn't, because HSTS would stop browsers from letting you accept a self-signed certificate.

The Local Certificate

Without a public certificate, the console is still encrypted with a certificate made for this host: ECDSA P-256, valid 825 days, covering the host name, <host>.local, localhost and the host's own addresses. The package creates it on installation and renews it on every upgrade when it's within 30 days of expiry or the host's names or addresses changed; sudo vh setup local-tls does the same on demand (--force regenerates it). The private key is /etc/vaulthalla/tls/local.key, readable by root only.

Browsers show a warning the first time because no public authority signed it. Compare the fingerprint, then accept it, or import /etc/vaulthalla/tls/local.crt into the client's trust store (see Trusting Certificates On Clients). For a certificate browsers trust without that step, use --certbot or --certbot-dns-cloudflare.

Package installation may already have set up the default HTTPS site when nginx was active and the checks were low risk. An unmodified packaged site from an earlier release, which served plain HTTP, is switched to HTTPS on upgrade; a site you changed, or one vh setup nginx generated without a certificate, is left alone and the upgrade prints a reminder. Running vh setup nginx again is safe: it regenerates the managed site and keeps the domain and S3 domain it recorded, so sudo vh setup nginx --certbot later adds a certificate for the domain already configured.

Before It Changes Anything

vh setup nginx refuses rather than overwrites when:

  • nginx isn't installed, or something other than nginx listens on ports 80/443;
  • the domain is already configured in another nginx site;
  • /etc/nginx/sites-available/vaulthalla exists, differs from the packaged template, and isn't Vaulthalla-managed.

It also checks the built-in admin password: if the generated initial password is still in use and its plaintext copy still exists, it offers to change it, delete the file and keep it, continue, or cancel. Without a terminal it warns and continues. Publishing the console with a default credential lying on disk is the mistake this prevents.

What It Configures

Item Path
Managed site /etc/nginx/sites-available/vaulthalla and its sites-enabled symlink
Managed marker /var/lib/vaulthalla/nginx_site_managed
Certificates /etc/letsencrypt/live/<domain>/ (Certbot), or /etc/vaulthalla/tls/local.{crt,key} (local)
Renewal hook (Cloudflare mode) /etc/letsencrypt/renewal-hooks/deploy/vaulthalla-nginx-reload.sh

Routes are described in What The Proxy Routes. The managed site turns proxy buffering off for /preview, /download and /upload, so decrypted downloads and media streams pass straight through and are never spooled to nginx's temporary files. Upgraded hosts with an older site still stream without buffering because the daemon sends X-Accel-Buffering: no on every streamed response.

On a fresh host without --domain, the unmodified distribution default site (/etc/nginx/sites-enabled/default) would shadow Vaulthalla on port 80, so setup disables that symlink and records it. apt remove, apt purge and vh teardown nginx restore it. A modified default site is never touched.

Let's Encrypt Over HTTP-01

1sudo vh setup nginx --domain vault.example.com --certbot

Setup validates Certbot's prerequisites, issues the certificate with Certbot's nginx plugin, and reloads nginx; if issuance fails it rolls back the low-risk changes it made. Renewals run from Certbot's own timer. Rerunning with --certbot when a certificate and HTTPS block already exist takes the renew-safe path.

--certbot cannot be combined with --s3-domain.

Cloudflare DNS-01 And The S3 Hostname

1sudo vh setup nginx --domain vault.example.com --s3-domain s3.vault.example.com \2  --certbot-dns-cloudflare /etc/vaulthalla/certbot/cloudflare.ini

DNS-01 proves ownership through a temporary TXT record written with the Cloudflare API, so Let's Encrypt never connects to the host: it works on LAN, lab and firewalled hosts. Vaulthalla requests one certificate covering both hostnames, writes both HTTPS server blocks itself and installs a deploy hook that reloads nginx after renewals.

The credentials file is a root-owned, 0600 Certbot file containing dns_cloudflare_api_token = <token>. Creating the token and the file, and the error messages, are covered step by step in S3 Gateway Setup. Certbot reads the file on every renewal, so keep it in place; package purge keeps /etc/vaulthalla/certbot/ for that reason.

Uploads Through nginx

Resumable uploads use paths under /upload, which the managed site already routes with client_max_body_size 0 and request buffering off. The /upload location sets no timeouts of its own, so nginx's 60-second defaults apply between successive reads and writes. That is enough: a part is answered once it is stored, and finishing an upload waits at most about five seconds because files are sealed in the background. Nothing needs changing for resumable uploads. See Uploads.

Share Port 443 With Vaulthalla Desktop

Vaulthalla Desktop normally reaches the node directly on port 36972 (Direct Device Connections). Where that port is blocked, nginx can route a dedicated device host name on port 443 to the device listener with a TLS passthrough. The console keeps its own name on the same port.

The passthrough routes at layer 4: a stream {} server reads the server name from the TLS ClientHello (ssl_preread) and forwards the encrypted connection unchanged. nginx never decrypts device traffic and needs no certificate for the device name. It can't terminate TLS for that name, because the device protocol's client certificate and pinned server key only work end to end.

Because the stream {} server takes port 443, the console's HTTPS servers in http {} move to a local port (127.0.0.1:8443 below), and the stream server routes every other name there. The public hop adds a PROXY protocol header, so the console still sees each client's real address (share rate limits and logs depend on it). The device listener doesn't read PROXY headers, so a second local hop removes the header before the device listener.

  1. Install the stream module

    Debian and Ubuntu ship it as a separate package:

    1sudo apt install libnginx-mod-stream
  2. Move the console's HTTPS servers off port 443

    In /etc/nginx/sites-available/vaulthalla, in every server block that has them (the console's, and the S3 host name's if you have one), replace

    1    listen 443 ssl;2    listen [::]:443 ssl;

    with

    1    listen 127.0.0.1:8443 ssl proxy_protocol;2    set_real_ip_from 127.0.0.1;3    real_ip_header proxy_protocol;

    Leave the port 80 redirect server as it is.

  3. Add the stream router

    Create /etc/nginx/vaulthalla-stream.conf, with your device host name in the map:

    1stream {2    # Route by the name in the TLS ClientHello; nothing is decrypted here.3    map $ssl_preread_server_name $vaulthalla_tls_route {4        device.example.com  127.0.0.1:8441;   # Vaulthalla Desktop -> device hop below5        default             127.0.0.1:8443;   # the console (and S3 host name) in http {}6    }7 8    server {9        listen 443;10        listen [::]:443;11        ssl_preread on;12        proxy_pass $vaulthalla_tls_route;13        proxy_protocol on;                    # the console learns the client's address14        proxy_connect_timeout 10s;15        proxy_timeout 1h;16    }17 18    # Device hop: accepts the PROXY header and passes the TLS stream on untouched.19    server {20        listen 127.0.0.1:8441 proxy_protocol;21        proxy_pass 127.0.0.1:36972;22        proxy_timeout 1h;23    }24}

    Then include it at the top level of /etc/nginx/nginx.conf, outside http {}, for example just before the http { line:

    1include /etc/nginx/vaulthalla-stream.conf;
  4. Reload and check

    1sudo nginx -t && sudo systemctl reload nginx2sudo ss -ltnp 'sport = :443'3sudo tail -n 20 /var/log/nginx/error.log

    nginx -t doesn't catch two servers claiming port 443. If one is left in http {}, the reload logs bind() to 0.0.0.0:443 failed (98: Address already in use) and nginx keeps running the previous configuration (a full restart would fail).

  5. Add the passthrough to config.yaml and restart the daemon:

    1device_server:2  advertise:3    public:4      - {host: device.example.com, port: 443, kind: passthrough}

    Point device.example.com at the host's public address with a DNS-only record. A Cloudflare-proxied (orange-cloud) record terminates TLS at Cloudflare and can never carry device connections.

The passthrough reaches the listener over loopback, so it works with remote connections off, and the node sees passthrough devices as 127.0.0.1. What that means is covered in TLS Passthrough On Port 443.

Rerunning vh setup nginx undoes the move

sudo vh setup nginx regenerates the managed site, which writes listen 443 ssl back into it. The reload then fails as described above: the running nginx keeps the old configuration, but nginx won't start at all on its next restart or reboot until you move the HTTPS servers to 127.0.0.1:8443 again. Package upgrades never rewrite an existing site file. After anything rewrites the site, check that no server in http {} listens on 443.

Check And Remove

1sudo nginx -t2systemctl status nginx3curl -I https://vault.example.com/4sudo vh teardown nginx

vh teardown nginx removes the Vaulthalla site and restores the distribution default site if setup disabled it; it leaves unrelated nginx configuration alone. VH_SKIP_NGINX_CONFIG=1 at install time opts out of automatic nginx setup, and that choice is remembered across upgrades until vh setup nginx opts back in.

vh setup nginx is a Linux command. On macOS, use Caddy.

Serve Vaulthalla With nginx | Vaulthalla