Liking cljdoc? Tell your friends :D

TLS, proxies and load balancers

An internet-facing instance needs TLS in front of it. There are two ways to get it:

SetupWhen
The portal is the proxy (below)One Linux server running the engine and its Apps. The portal terminates TLS, gets certificates from Let's Encrypt (or uses yours), and routes App hostnames. Nothing else to install.
Your own reverse proxy (nginx, Caddy, Traefik)You already run one, or the instance sits behind a load balancer that terminates TLS.

The portal as the proxy

The portal (the synthigy process that supervises the engine) can own the public port itself. The engine and every App then listen on loopback only, and the portal passes each request on by its Host:

  • a hostname an App owns (<app>.<apps domain>) goes to that App;
  • everything else goes to the engine, so the engine's own name, an IP address or localhost:7887 keep working.

SYNTHIGY_PROXY_MODE picks the mode:

ModeThe public port
offThe engine binds SYNTHIGY_SERVER_PORT itself. No Apps routing.
httpThe portal answers plain HTTP and routes. synthigy env init writes this into every new .env. Use it on a dev box (<app>.localhost), or behind a load balancer that terminates TLS.
tlsThe same on TLS, with certificates from files or ACME. What a server install sets.

A server in one command

On a Linux server with systemd, as root, once:

# certificates from Let's Encrypt
sudo synthigy service install --domain box.example.com --email ops@example.com

# or your own certificate (a company CA, a bought wildcard)
sudo synthigy service install --domain box.example.com --cert fullchain.pem --key key.pem

It installs Podman when missing, creates the system user synthigy, moves your existing instance into /var/lib/synthigy/.synthigy (--fresh starts empty), and writes the server settings into its .env: the root URL https://box.example.com, SYNTHIGY_PROXY_MODE=tls and port 443. systemd opens ports 443 and 80 and hands them to the service, so the service itself runs without privileges, and the ports stay open while it restarts. A rerun is safe, and is how you change any of these options later. A bare profile (no sign-in) becomes full: the TLS front refuses to serve a bare engine.

Before you run it:

  • DNS: an A/AAAA record for the engine's name, and a wildcard record for App names (*.box.example.com, or *.<apps domain> with --apps-domain). The install prints the records it finds.
  • Firewall: 443 and 80 open to the internet. The install warns when ufw or firewalld is active. Port 80 is needed for redirects and for the HTTP-01 challenge.
  • Nothing else on 443 or 80. The install refuses and names the program that holds them.

--apps-domain example.com with --domain engine.example.com puts Apps beside the engine (shop.example.com) instead of under it (shop.engine.example.com). One *.example.com certificate then covers the engine and every App.

Afterwards, synthigy portal prints the tunnel to the portal page, which the server serves only on a socket: ssh -L 7888:/run/synthigy/portal.sock <host> from an account in group synthigy. systemctl status synthigy and journalctl -u synthigy show the service.

Certificates

From ACME (no --cert): one certificate per name, issued before the first visitor arrives. The engine's name is issued when the portal starts, and an App's names when the App is deployed. Every name is renewed 30 days before it expires.

  • Challenges: TLS-ALPN on 443, or HTTP-01 on 80. One of them must reach the server from the internet.
  • Only routed names are issued. The engine's name and the hostnames of deployed Apps. A stranger's SNI never reaches the CA.
  • Failures back off, from 1 minute to 1 hour per name, so a broken DNS record does not use up Let's Encrypt's limit (5 failed validations per name per hour). The portal page's Certificates panel shows each name: ok, pending or failed, with the CA's error. A certificate that has less than 20 days left and has not been renewed shows as failed.
  • Testing: --acme-url https://acme-staging-v02.api.letsencrypt.org/directory issues from Let's Encrypt's staging CA. A company ACME server works the same way; when its TLS uses an internal CA, set SYNTHIGY_CA_BUNDLE.
  • Stored in <instance>/certs/acme/<CA host>/. A restart serves what is stored. Back this folder up with the instance.
  • Wildcards (DNS-01) are not supported yet.

From files (--cert/--key, or SYNTHIGY_PROXY_CERT/SYNTHIGY_PROXY_KEY): the chain must cover the engine's name and *.<apps domain>. A wildcard covers one label, so App names stay one level deep. A mismatched pair, or an expired one, stops the start with the reason. Renewed files are picked up within seconds, with no restart; a half-written file is ignored and the old pair keeps serving. Files win over ACME when both are set.

You can switch between ACME and files in the Certificates panel while the portal serves.

What the portal does to every request

  • Rewrites the forwarding headers. X-Forwarded-For, X-Real-Ip, X-Forwarded-Host, X-Forwarded-Proto and Forwarded are always set by the portal. A visitor's own copies are dropped, unless the request comes from a trusted edge listed in SYNTHIGY_PROXY_TRUST. The engine behind it is configured to trust only the portal.
  • Streams without buffering: server-sent events, long downloads and App WebSockets pass through.
  • Redirects plain HTTP on port 80 to https:// (308, path and query kept). Only a request from the machine itself naming localhost is served over plain HTTP, so local tools work without a certificate. SYNTHIGY_PROXY_HTTP_PORT moves port 80, and off closes it.
  • Limits: App request bodies up to 64 MB (the engine keeps its own limits). Idle connections close after 2 minutes. A request body gets 10 minutes.
  • Checks who holds a backend port before connecting (Linux), so another local account cannot take over the engine's or an App's loopback port while it restarts. A target that does not answer is a 502.

Behind a load balancer

When a load balancer terminates TLS (an AWS ALB, a cloud LB, a company gateway), let it, and run the portal in http mode behind it:

SYNTHIGY_PROXY_MODE=http
SYNTHIGY_SERVER_PORT=8080                        # the port the load balancer targets
SYNTHIGY_PROXY_TRUST=10.0.1.0/24,10.0.2.0/24     # the load balancer's subnets
SYNTHIGY_IAM_ROOT_URL=https://box.example.com    # required: the portal only sees http

The portal keeps the load balancer's X-Forwarded-* chain and takes the client as the right-most address that is not a trusted edge. Point the health check at GET /health. Forward App hostnames to the same target; the portal routes them.

Without the server install

The same front works on any machine, set by hand in the instance's .env. These are what the install writes:

SYNTHIGY_PROXY_MODE=tls
SYNTHIGY_SERVER_PORT=443
SYNTHIGY_IAM_ROOT_URL=https://box.example.com
SYNTHIGY_PROXY_ACME_EMAIL=ops@example.com        # ACME, or:
# SYNTHIGY_PROXY_CERT=/path/fullchain.pem
# SYNTHIGY_PROXY_KEY=/path/key.pem
SYNTHIGY_APPS_DOMAIN=example.com                 # optional

Ports below 1024 need privileges. Without systemd handing the ports over, either allow unprivileged binds once per host (net.ipv4.ip_unprivileged_port_start=80 in /etc/sysctl.d/), or use high ports and forward to them. The full list of proxy settings is in ENV.md under Proxy and apps.

Check it: the portal page's Diagnostics shows the mode, the public port and the engine's loopback port; curl -I https://box.example.com/health answers 200.


Your own reverse proxy

With your own proxy in front, pick how it reaches the instance:

  • SYNTHIGY_PROXY_MODE=http (the default for new instances): your proxy forwards to the portal on SYNTHIGY_SERVER_PORT, and the portal still routes App hostnames. List your proxy in SYNTHIGY_PROXY_TRUST (e.g. 127.0.0.1/32 for a proxy on the same machine). The portal sets the engine's own trust to loopback, so SYNTHIGY_SERVER_TRUST_PROXY below is not needed.
  • SYNTHIGY_PROXY_MODE=off: the engine binds the port itself and the settings below apply as written. Apps are not routed.

Everything else in this section applies to both.

Engine settings

# reachable only through the proxy
SYNTHIGY_SERVER_HOST=127.0.0.1
SYNTHIGY_IAM_ROOT_URL=https://synthigy.example.com
SYNTHIGY_SERVER_TRUST_PROXY=127.0.0.1/32,::1/128
  • TLS is required. Session cookies are Secure; over plain http:// the login page accepts the password and comes straight back.
  • SYNTHIGY_IAM_ROOT_URL is the public origin: token issuer and base of every login link. Unset, it is taken from X-Forwarded-Host/-Proto per request, which is wrong behind a load balancer, or from Host when the proxy isn't trusted. The portal flags it until set.
  • SYNTHIGY_SERVER_TRUST_PROXY lists your proxies (IPs or CIDRs). Only requests from them have X-Forwarded-For, -Host and -Proto believed; from anyone else those headers are dropped. Synthigy reads X-Forwarded-For from the right and skips your proxies, so a client can't fake its address. It can only find the address the first hop recorded: behind a load balancer, the proxy on the instance must keep that record, not overwrite it — see Behind an AWS load balancer. In a container network, list the proxy's subnet.
  • An X-Request-Id from a trusted proxy becomes the request id.

What the proxy must do

  • Stream without buffering on /data/events and /console/live/* (server-sent events, keepalive every 15–20s): buffering and compression off, read timeout well above that. A buffering proxy looks like a frozen console. The engine uses no WebSockets; an App may, so pass Upgrade through for App hostnames.
  • Give the instance its own hostname and pass paths through unrewritten — no subpath mounting, no StripPrefix.
  • Don't add CORS headers; Synthigy sends its own (CORS.md).
  • Raise the body limit to about 64m for writes, deploys and IAM imports.
  • Health check: GET /health, 200 while the node can serve, 503 when it can't (OPERATIONS.md).
  • Set SYNTHIGY_IAM_ROOT_URL, or keep the public Host. With neither, a proxy that sends Host: localhost over plain http makes the engine treat itself as a local dev install, and it issues the session cookie without Secure. Forwarding X-Forwarded-Proto and X-Forwarded-Host helps only when the proxy is listed in SYNTHIGY_SERVER_TRUST_PROXY; otherwise the engine drops those headers.
  • Never proxy the portal page (port 7888, any free port for a project's .synthigy/, or the socket of a server install; synthigy portal prints which): it trusts anything from 127.0.0.1, so a local proxy would publish it. Reach it with ssh -L 7888:127.0.0.1:7888 <host>, with that port in place of 7888.
  • Firewall 7887 so nothing bypasses the proxy.

The configs below are for a proxy that faces the internet itself. Behind a load balancer, see the last section.

nginx

Write proxy_pass http://synthigy; with no path after the host: a trailing / makes nginx strip the location prefix, and routes 404.

upstream synthigy {
    server 127.0.0.1:7887;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name synthigy.example.com;
    return 301 https://$host$request_uri;
}

server {
    # works on nginx 1.14+; on 1.25.1+ you may use `listen 443 ssl;` + `http2 on;`
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name synthigy.example.com;

    ssl_certificate     /etc/letsencrypt/live/synthigy.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/synthigy.example.com/privkey.pem;

    client_max_body_size 64m;

    proxy_http_version 1.1;
    # needed by `keepalive` in the upstream block
    proxy_set_header Connection        "";
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $server_port;

    location / {
        proxy_pass http://synthigy;
        proxy_read_timeout 75s;
    }

    location /console/assets/ {
        proxy_pass http://synthigy;
        proxy_cache_valid 200 1h;
    }

    location = /data/events {
        proxy_pass http://synthigy;
        proxy_buffering off;
        proxy_cache off;
        gzip off;
        proxy_read_timeout 1h;
        proxy_send_timeout 1h;
    }

    location ^~ /console/live/ {
        proxy_pass http://synthigy;
        proxy_buffering off;
        proxy_cache off;
        gzip off;
        proxy_read_timeout 5m;
        proxy_send_timeout 5m;
    }
}

Caddy

synthigy.example.com {
	@sse  path /data/events /console/live/*
	@rest not path /data/events /console/live/*

	encode @rest zstd gzip

	reverse_proxy @sse 127.0.0.1:7887 {
		header_up X-Forwarded-For {remote_host}
		flush_interval -1
		transport http {
			read_timeout 0
			compression off
		}
	}

	reverse_proxy 127.0.0.1:7887 {
		header_up X-Forwarded-For {remote_host}
	}
}

Caddy obtains the certificate itself. {remote_host} replaces the client-supplied X-Forwarded-For rather than appending to it — right when Caddy is the edge, wrong behind a load balancer.

Traefik v3

Static (traefik.yml) — with no trustedIPs, Traefik drops a client-supplied X-Forwarded-For and writes the real peer address itself, which is what Synthigy needs. Add trustedIPs only for a load balancer in front of Traefik.

entryPoints:
  web:
    address: ":80"
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: ":443"
    forwardedHeaders:
      insecure: false

certificatesResolvers:
  le:
    acme:
      email: ops@example.com
      storage: /letsencrypt/acme.json
      httpChallenge:
        entryPoint: web

providers:
  file:
    filename: /etc/traefik/dynamic.yml
    watch: true

Dynamic (dynamic.yml) — one router for the whole host, no path rewriting:

http:
  routers:
    synthigy:
      rule: "Host(`synthigy.example.com`)"
      entryPoints:
        - websecure
      service: synthigy
      tls:
        certResolver: le

  services:
    synthigy:
      loadBalancer:
        servers:
          - url: "http://127.0.0.1:7887"
        passHostHeader: true
        responseForwarding:
          flushInterval: "100ms"

As Docker labels instead of the file provider:

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.synthigy.rule=Host(`synthigy.example.com`)"
  - "traefik.http.routers.synthigy.entrypoints=websecure"
  - "traefik.http.routers.synthigy.tls.certresolver=le"
  - "traefik.http.services.synthigy.loadbalancer.server.port=7887"
  - "traefik.http.services.synthigy.loadbalancer.responseforwarding.flushinterval=100ms"

Behind an AWS Application Load Balancer

client → ALB (TLS) → proxy on the instance, port 80 → engine on 127.0.0.1:7887

Each hop sees only the machine connected to it. The ALB records the client in X-Forwarded-For; the proxy on the instance sees the ALB. A proxy that overwrites the header with its own peer, as the configs above do, makes every request look like it came from the ALB. Make the proxy trust the ALB and take the client from the header instead; SYNTHIGY_SERVER_TRUST_PROXY then stays at loopback.

ALB

  • X-Forwarded-For header: Append (the default). Leave client port preservation off.
  • Terminate TLS on the ALB and redirect HTTP to HTTPS with an ALB listener rule. The proxy only ever receives HTTP from the ALB, so a redirect there loops.
  • Target the instance's port 80, health check GET /health. The default 60s idle timeout is above the 15–20s event-stream keepalive.
  • Allow port 80 on the instance only from the ALB's security group.
  • Identify the ALB by the subnets it is attached to: its node addresses change as it scales.

Engine: the settings at the top. SYNTHIGY_IAM_ROOT_URL is not optional here — the proxy receives plain HTTP, so anything derived from the request says http://.

nginx — replaces both server blocks of the nginx config; keep its upstream and location blocks. Needs ngx_http_realip_module, included in the distribution packages.

server {
    listen 80;
    server_name synthigy.example.com;

    # one line per subnet the ALB is attached to
    set_real_ip_from  10.0.1.0/24;
    set_real_ip_from  10.0.2.0/24;
    real_ip_header    X-Forwarded-For;
    real_ip_recursive on;

    client_max_body_size 64m;

    proxy_http_version 1.1;
    proxy_set_header Connection        "";
    proxy_set_header Host              $host;
    # $remote_addr is the client once realip has run
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $remote_addr;
    proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $http_x_forwarded_port;

    # location blocks as in the nginx config
}

Caddy 2.8+

{
	servers {
		trusted_proxies static 10.0.1.0/24 10.0.2.0/24
		trusted_proxies_strict
	}
}

http://synthigy.example.com {
	@sse  path /data/events /console/live/*
	@rest not path /data/events /console/live/*

	encode @rest zstd gzip

	reverse_proxy @sse 127.0.0.1:7887 {
		header_up X-Forwarded-For {client_ip}
		flush_interval -1
		transport http {
			read_timeout 0
			compression off
		}
	}

	reverse_proxy 127.0.0.1:7887 {
		header_up X-Forwarded-For {client_ip}
	}
}

trusted_proxies_strict makes Caddy read the header from the right; without it Caddy takes the leftmost entry, which the client wrote. http:// in the site address leaves TLS to the ALB, and the ALB's X-Forwarded-Proto: https passes through because the ALB is trusted.

Traefik: set forwardedHeaders.trustedIPs to the ALB subnets on the entry point the ALB targets, and drop the web → websecure redirect (the ALB redirects). Traefik keeps the ALB's entries and appends its own peer rather than resolving the client, so add the ALB subnets to SYNTHIGY_SERVER_TRUST_PROXY as well.

Check it: request log lines carry ip, the resolved client. Behind a correctly configured ALB it is your public address, never a 10.x one.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close