Skip to content
Docs
opendesk.shOpen app

Your own reverse proxy

Run opendesk behind Traefik, nginx, Nginx Proxy Manager or a Caddy you already run, instead of the bundled Caddy.

The self-host bundle comes with Caddy, which takes ports 80 and 443 and gets the certificates itself. If the machine already has a reverse proxy that handles TLS and routing for other services, turn the bundled Caddy off and point your proxy at opendesk instead.

Internet → your proxy (TLS) → opendesk :8080 everything else
→ realtime :4000 /socket/* (WebSocket)
Terminal window
curl -fsSL https://opendesk.sh/install.sh | sh -s -- --proxy external --domain desk.example.com

On an existing install, run it again with --proxy external. Later runs and opendesk-ctl upgrade keep the mode, and --proxy caddy switches back.

compose.external-proxy.yml changes three things: Caddy no longer starts, opendesk and realtime are published over plain HTTP for your proxy, and both read the client address from your proxy’s X-Forwarded-For (see Client addresses).

Variable Default Meaning
OPENDESK_BIND 127.0.0.1 Host address the two ports are published on. 127.0.0.1 is reachable from this machine only.
OPENDESK_PORT 8080 Host port for opendesk: the API, web app, widget, help centers and admin panel.
REALTIME_PORT 4000 Host port for the realtime gateway.
TRUSTED_PROXY_HOPS 1 Proxies in front that append to X-Forwarded-For.

If you use a docker-compose.override.yml, add it to COMPOSE_FILE as well: once COMPOSE_FILE is set, Compose stops loading it on its own.

A proxy running in Docker (Traefik, Nginx Proxy Manager) cannot reach 127.0.0.1 on the host. Connect it to the opendesk_proxy network instead, and it reaches the services by name, at opendesk:8080 and realtime:4000:

Terminal window
docker network connect opendesk_proxy <your proxy container>

Only opendesk and realtime are on that network. Postgres is not.

Requests Go to Notes
/socket/* on the main host realtime, port 4000 WebSocket upgrades. Agents, the chat widget (/socket/widget/*) and the apps connect here.
Everything else on the main host opendesk, port 8080 The API, web app, /widget/v1.js, /config.js, /help/<slug>, /admin/.
<slug>.HELP_DOMAIN and custom help center domains opendesk, port 8080 Only if you use them. See Help centers.

What opendesk needs from the proxy:

  • TLS. The proxy serves https:// and wss://. opendesk and realtime speak plain HTTP behind it. opendesk takes the scheme from OPENDESK_URL, so X-Forwarded-Proto is optional.
  • The Host header as the browser sent it. Help centers are chosen by host. Most proxies keep it by default; nginx needs proxy_set_header Host $host.
  • WebSocket upgrades on /socket/, with a read timeout of a minute or more. Sockets send a heartbeat every 25 seconds, and the gateway closes one that is silent for 60.
  • The Origin header passed on. The gateway refuses agent sockets from an origin other than CHECK_ORIGINS (default OPENDESK_URL).
  • Request bodies up to 30 MB. Attachments are up to 25 MB. nginx allows 1 MB unless told otherwise.
  • No response buffering for streams. AI answers stream as server-sent events. opendesk sends X-Accel-Buffering: no, which nginx honours.

Rate limits on sign-in, sign-up and the public endpoints, and the IP in the audit log, use the client’s address. Behind a proxy, opendesk sees the proxy’s address, so it reads the client from X-Forwarded-For.

TRUSTED_PROXY_HOPS is the number of proxies in front of opendesk that add an entry to X-Forwarded-For. opendesk takes the address that many entries from the right: the one your outermost proxy saw. Anything a client puts in the header itself is further left and ignored, so the address cannot be forged to get around a rate limit.

In front of opendesk TRUSTED_PROXY_HOPS
Your proxy 1 (the default in compose.external-proxy.yml)
Cloudflare (proxied DNS), then your proxy 2
A cloud load balancer, then your proxy 2

Set it in .env. It applies to opendesk and the realtime gateway. Make sure your proxy appends to X-Forwarded-For or sets it to the peer’s address (nginx’s $proxy_add_x_forwarded_for, Traefik’s and Caddy’s defaults), and that opendesk’s ports are reachable only through it. A client that reaches port 8080 directly could write any X-Forwarded-For it likes.

The apps open the realtime connection with a short-lived token in the Sec-WebSocket-Protocol header. Don’t log that header for /socket/, and don’t log query strings anywhere: sign-in callbacks and signed file links carry codes and signatures in them. Turn off the /socket/ access log, or log paths alone. opendesk itself never logs query strings, Authorization or cookies, and the bundled Caddy drops them from its log. The examples below do the same.

Replace desk.example.com with your domain. These were tested with the services published on the host, or reached by name on opendesk_proxy.

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 443 ssl;
http2 on;
server_name desk.example.com;
ssl_certificate /etc/letsencrypt/live/desk.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/desk.example.com/privkey.pem;
# Attachments are up to 25 MB.
client_max_body_size 30m;
location /socket/ {
# The realtime token rides in the connection's query string: keep it out of logs.
access_log off;
proxy_pass http://127.0.0.1:4000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 1h;
proxy_send_timeout 1h;
}
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# AI answers stream for a while.
proxy_read_timeout 5m;
}
}
server {
listen 80;
server_name desk.example.com;
return 301 https://$host$request_uri;
}

Each brand’s help center is at https://desk.example.com/help/<slug> with no more setup. If you give them hosts of their own (HELP_DOMAIN or custom domains), your proxy has to serve those hosts too and send them to opendesk on port 8080 with the Host header unchanged:

  • <slug>.HELP_DOMAIN: one wildcard certificate for *.help.example.com (DNS challenge) and a server or router matching that wildcard.

  • Custom domains (help.acme.com): the names are not known in advance, so the proxy needs certificates issued on demand. Caddy does it with on_demand_tls, asking opendesk whether a name belongs to one of its help centers before it requests a certificate:

    {
    on_demand_tls {
    ask http://127.0.0.1:8080/v1/public/help-domains/tls
    }
    }
    https:// {
    tls {
    on_demand
    }
    reverse_proxy 127.0.0.1:8080
    }

    With a proxy that cannot do this, add each custom domain to it by hand.

  • Attachments with the minio profile. Downloads are presigned URLs on S3_ENDPOINT, so browsers must reach it. Put the s3 service on the proxy network in your own compose file and route a host to s3:9000.
  • Inbound mail. Unchanged: the built-in SMTP receiver (smtp-inbound profile) has its own port and never goes through the proxy.
  • Logs. There is no caddy service, so opendesk-ctl logs caddy has nothing to show. Your proxy’s access log should not record query strings or the Sec-WebSocket-Protocol header on /socket/: realtime tokens travel there.
Terminal window
curl -fsS -o /dev/null -w '%{http_code}\n' https://desk.example.com/readyz

200 means opendesk is up and connected to Postgres and NATS. Then sign in: the inbox updating as you work means the WebSocket goes through. If it does not, the browser’s developer tools show the /socket/websocket request. A 403 there is an Origin that does not match CHECK_ORIGINS. Any other failure to upgrade is usually a proxy that does not pass the Upgrade and Connection headers.

Edit this page on GitHub