Matrix hosting tips
I’ve recently re setup my Matrix server and there were a few things I wish would have been slightly easier to find. So here they are.
I’m running Dendrite, so some things may be slightly different to Synapse or some other homeservers, but this is mostly just tips on Matrix hosting in general.
Dendrite is running in a VM on a server in my office, and is exposed to the Internet via Traefik running on a cheap VPS. Traefik can talk to Dendrite over Tailscale.
Ports
Matrix expects to find your homeserver on port 8448. Dendrite by default listens on port 8008, but this is configurable with the --http-bind-address
CLI flag.
You can really have your homeserver listen on whichever port you like, as long as you configure that in delegation (see below).
Domain / Delegation
I’m @me:ideclon.uk. I needed to have Traefik forward /_matrix
to my Matrix server (and there’s also /_dendrite
for the Dendrite API, but that’s not required). But you don’t need to run your homeserver on the same webserver as your website. For some of my other homeservers, their domains are at matrix.[DOMAIN_NAME]
, but I still want the users to be @[USERNAME]:[DOMAIN_NAME]
! To do this, you’ll need delegation.
There are two basic ways to do delegation - well-known
and DNS SRV.
Well-known
You just need to serve the following two files on your website:
/.well-known/matrix/server
:
{
"m.server": "[MATRIX_HOMESERVER]:[MATRIX_PORT]"
}
/.well-known/matrix/client
:
{
"m.homeserver": {
"base_url": "https://[MATRIX_HOMESERVER]:[MATRIX_PORT]/"
}
}
You must set Access-Control-Allow-Origin *
on both of these files. I do this with a .htaccess
file in the /.well-known/matrix
directory:
Header add Access-Control-Allow-Origin "*"
DNS SRV
The Dendrite docs do a good enough job of this - https://matrix-org.github.io/dendrite/installation/domainname#dns-srv-delegation