Tin Hat / Run a server / Your own domain

Your own domain

For people who own a domain or already run a reverse proxy. Your server lives at an address like chat.example.com, gets its certificate through your DNS provider or your own proxy, and nothing depends on tinhat.me.

AdvancedCloudflare · Porkbun · deSEC · DuckDNSnginx · Caddy · Traefik · NPM

Most groups don't need this. Friends anywhere gives your server a name like crew.tinhat.me with nothing to set up. Choose your own domain if you already own one and want your server's name to be yours, or if a reverse proxy already handles the web traffic in your home.

Two ways to use your own domain

At setup, the Name step has a third choice, My own domain Advanced. It asks for your server's full address, then where the domain's DNS is, or who handles HTTPS:

Through your DNS provider

You paste API details from Cloudflare, Porkbun, deSEC or DuckDNS. The server gets its own certificate and has port 443 to itself, like a tinhat.me server.

Certificate
Let's Encrypt, through your provider's API
Address record
Cloudflare: the server keeps it pointing home. The others: you do
Router
TCP 443, TCP 7881 and UDP 7882, opened automatically on most routers

Behind your own reverse proxy

Your nginx, Caddy, Traefik or Nginx Proxy Manager keeps port 443 and its certificate, and passes the domain on to the Tin Hat server.

Certificate
Your proxy's, like for your other sites
Address record
Yours, wherever your domain's DNS is
Router
443 stays with your proxy; the server asks only for TCP 7881 and UDP 7882

Either way, your friends type the whole domain in the Tin Hat app (chat.example.com), and everyone's address looks like @alex:chat.example.com. Nothing about your domain depends on tinhat.me.

Before you start

  • A domain you own, or one of your names under duckdns.org.
  • Pick an address you'll keep. It's part of every account on the server (@alex:chat.example.com). It can change later (moving to your own domain), but everyone then signs in again.
  • Give the server a name of its own, like chat.example.com. With Cloudflare the server sets that name's address record itself, so don't use a name your website already uses.
  • For the DNS-provider way: your domain's DNS at Cloudflare, Porkbun, deSEC or DuckDNS, and API access there (how-tos below). DNS somewhere else? Use the reverse-proxy way.
  • For the reverse-proxy way: a proxy on your home network that already has port 443 and gets its own certificates. It can also run on the same Linux machine as Tin Hat, at home or on a rented server (--behind-proxy).
  • A fixed address for the server on your home network (a DHCP reservation), so the forwarded ports and your proxy keep finding it.
  • Internet that takes incoming connections. Behind carrier NAT (most 5G home internet and Starlink) friends can't reach a server at your own domain. A rented server works instead: the Linux script on a VPS, with your domain pointing at it.

Through your DNS provider

To get a certificate, the server proves to Let's Encrypt that it controls your domain by adding a short-lived record through your provider's API (a "DNS-01" check). So no port needs to be open for the certificate, and it renews by itself every couple of months.

  • Cloudflare is the easiest. The server also keeps your domain's address record (an A record) pointing at your home, checking every ten minutes. It sets the record to DNS only (grey cloud): calls can't pass through Cloudflare's proxy.
  • Porkbun, deSEC and DuckDNS: the certificate works the same way, but pointing the domain at your home stays your job: an A record with your home's public address. If your internet provider changes that address now and then, your router's dynamic DNS can keep the record current. The setup and the dashboard check where the domain points and tell you when it's wrong.
  • Your API details stay on your server (and in its encrypted backups). They're never sent to Tin Hat.

Cloudflare

  1. In Cloudflare: My Profile → API Tokens → Create Token, with two permissions for this domain's zone: Zone → Zone → Read and Zone → DNS → Edit. Copy the token.
  2. At setup, choose Cloudflare and paste it as the Cloudflare API token.
  3. That's it: during the install the server points the domain at your home, and keeps it there.

Porkbun

  1. In Porkbun: Account → API Access: create an API key, and switch on API access for this domain.
  2. At setup, choose Porkbun and paste the API key and the Secret API key.
  3. Point the domain at your home yourself: an A record with your home's public address (the setup shows it if it's wrong), or your router's dynamic DNS.

deSEC

  1. In deSEC: Token Management → add a token.
  2. At setup, choose deSEC and paste the Token.
  3. Point the domain at your home yourself: an A record with your home's public address, or your router's dynamic DNS.

DuckDNS

  1. Your server's address is one of your names under duckdns.org, like crew.duckdns.org.
  2. At setup, choose DuckDNS and paste the token shown on your DuckDNS page.
  3. Keep the name pointing at your home yourself, the way you already do for DuckDNS (your router's dynamic DNS, for example).

At setup

  1. On the Name step, choose My own domain.
  2. Your server's address: the full domain, like chat.example.com.
  3. Where the domain's DNS is, or who handles HTTPS: your DNS provider, then paste its API details. Or My own reverse proxy (it handles HTTPS) (below).
  4. Make your admin account, check the summary, and press Install Tin Hat Server.
Name your server, with My own domain chosen: the address chat.example.com, Cloudflare as the DNS provider, and the Cloudflare API token
The Name step with My own domain and Cloudflare.

The install starts with one extra step, Pointing your domain at your home. With Cloudflare, the server points the domain at your home's public address itself. With the others, it checks the address is already right and tells you if not. Then it gets its certificate, opens the ports on your router and checks from outside, like any server reachable from anywhere (the install, step by step).

The outside check uses the Tin Hat names service even for your own domain, because something outside your home has to connect back. Your server has no account there, so it solves a few seconds of number-crunching instead, and the service connects back only to the address the request came from, with your domain as the name.

Behind your own reverse proxy

If nginx, Caddy, Traefik or Nginx Proxy Manager already answers on port 443 in your home and gets its own certificates, keep it that way. At setup, choose My own reverse proxy (it handles HTTPS):

Where the domain's DNS is, or who handles HTTPS: My own reverse proxy (it handles HTTPS), with its explanation: this server listens on port 8080 for it, and asks your router only for the call ports
  • Your proxy keeps port 443 and the certificate for your domain, and sends the domain to http://<the server's home address>:8080. That port only answers addresses on your home network and the machine's own, so the proxy has to be on your home network or on the same machine.
  • Calls don't go through the proxy. The server asks your router only for TCP 7881 and UDP 7882, which come straight to it.
  • Your domain points at your home, at your DNS provider, like your other sites.
  • Give the server a fixed address in your router (a DHCP reservation), so the proxy keeps finding it.
  • Proxy and Tin Hat on the same Linux machine? Install with --behind-proxy: Tin Hat leaves ports 80 and 443 to your proxy, its setup answers on port 8080, and this choice is already made for you (how).

When the install is done, the last page of the setup and Dashboard → Network show the settings for all four proxies, with your domain, the server's address and your upload limit filled in, ready to copy.

The settings

Here they are with example values: the domain chat.example.com, the server at 192.168.1.50 on your home network, and files up to 100 MB (so requests may be up to 105 MB: the file, plus some room). Use the dashboard's copy for your own.

# Once, in the http { } block (WebSockets for calls' sign-in):
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name chat.example.com;
    # ssl_certificate and ssl_certificate_key: your certificate for chat.example.com

    client_max_body_size 105m;

    location / {
        proxy_pass http://192.168.1.50: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;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 600s;
        proxy_buffering off;
    }
}

Add your own ssl_certificate lines. The map block goes once in the http { } block, not inside the server. In our lab these settings went into /etc/nginx/conf.d as they are, with nginx on the same machine as Tin Hat.

chat.example.com {
	reverse_proxy 192.168.1.50:8080
}

Caddy gets its certificate and passes WebSockets and the visitor's address on by itself. This is the setup we tested in our lab, behind an owner's Caddy.

# In a file-provider (dynamic configuration) file:
http:
  routers:
    tinhat:
      rule: "Host(`chat.example.com`)"
      entryPoints: [websecure]
      service: tinhat
      tls:
        certResolver: letsencrypt  # your certificate resolver's name
  services:
    tinhat:
      loadBalancer:
        servers:
          - url: "http://192.168.1.50:8080"
Hosts → Proxy Hosts → Add Proxy Host
Details: Domain Names chat.example.com, Scheme http, Forward Hostname / IP 192.168.1.50, Forward Port 8080, Websockets Support on
SSL: Request a new SSL Certificate, Force SSL on
Advanced (custom Nginx configuration): client_max_body_size 105m;

Websockets Support has to be on: calls' sign-in uses them. The client_max_body_size line lets people send files up to your upload limit.

Then press Check again on the dashboard's Network tab. Until the proxy passes your domain on, the check says Your reverse proxy doesn't pass https://chat.example.com on to this server yet, with what to look at: the proxy's settings, that your router sends TCP 443 to the proxy, and that the domain points at your home.

How it works underneath: port 8080 answers only home-network addresses and the machine's own, and takes the visitor's address from your proxy's X-Forwarded-For header (so the server sees each friend's own address, not your proxy's). The server's own parts reach it over its own certificate on its own loopback address, never through your proxy (except when it's installed next to your proxy on the same Linux machine with --behind-proxy: then it has no certificate of its own and checks call sign-ins through your proxy).

After setup

The dashboard's Network tab gets two extra cards:

  • Your domain: where your domain points right now (asked of public DNS resolvers), next to your home's public address, with Points home or Points elsewhere, and who keeps it current. With Cloudflare the server fixes a wrong address within ten minutes; with the others it tells you what record to set.
  • Your reverse proxy (behind a proxy): where to send the domain, and the settings for nginx, Caddy, Traefik and Nginx Proxy Manager, each with a Copy button.
The Network tab of a server behind its owner's reverse proxy: friends outside can reach it; Your domain points home; Your reverse proxy with tabs for nginx, Caddy, Traefik and Nginx Proxy Manager
Dashboard → Network behind your own reverse proxy (the 0.3.1 dashboard, shown with example values).

Questions

Can I move an existing server to my own domain?

Yes: dashboard → Maintenance → Move to your own domain. Type the new address, pick its DNS provider (or your own reverse proxy), press Check, then type the address again to confirm. Every account, room and message moves with the server; chat pauses for a few minutes, longer with a long history.

Everyone signs in again at the new address with the same username and password, then unlocks with their Security Key, and their messages come back. Without the Security Key, older encrypted messages can't be read (new ones work). Friends who had verified each other do it once more.

Behind your own reverse proxy, set the proxy up for the new address first (Check shows the settings for nginx, Caddy, Traefik and Nginx Proxy Manager): the move checks that the address leads to your server before anything changes. If something goes wrong before people can use the new address, the server goes back to how it was, under its old address; a problem after that (say, with calls) stays on the card with what to fix.

The old address keeps answering (apps that still use it are told the new one; behind your own proxy, only while the proxy sends it to the server) until you let go of it on the same card; pictures and files from before the move keep opening either way. A tinhat.me name you let go of can't be used again, by you or anyone.

Not possible: a server connected to other servers (Other Tin Hat servers or Other Matrix servers on the Network tab): disconnect or remove them first, move, then connect again.

My domain's DNS isn't at one of those four

Use the reverse-proxy way: your proxy gets the certificate, and the domain's records stay wherever they are. Or move the domain's DNS to Cloudflare, Porkbun, deSEC or DuckDNS.

Can friends type just the first part, like with tinhat.me?

No. Short names like crew are for tinhat.me names. With your own domain, friends type the whole address: chat.example.com.

Does it still need anything from Tin Hat?

Only for the check from outside. To learn your home's public address, the server asks the Tin Hat names service first; when that doesn't answer, it asks a public "what's my address" service instead (1.1.1.1's /cdn-cgi/trace, then api.ipify.org), so the address calls use and, with Cloudflare, the domain's record still follow a change. If the names service went away, your server would keep working; only the check from outside would stop. What leaves your home.

My internet is 5G home internet or Starlink

Those usually share one public address between many homes ("carrier NAT"), so friends can't reach a server at home, at your own domain or at a tinhat.me name. A server for your home works either way, and a rented server (a VPS) with the Linux script works for friends anywhere. More.