Example: using the root domain as the homeserver name
<= Back to Generic Deployment Guide
It is possible to host tuwunel on a subdomain such as matrix.example.com but delegate from example.com as the server name. This means that usernames will be @user:example.com rather than @user:matrix.example.com.
Federating servers and clients accessing tuwunel at example.com will attempt to discover the subdomain by accessing the example.com/.well-known/matrix/client and example.com/.well-known/matrix/server endpoints. These need to be set up to point back to matrix.example.com.
Note
In all of the following examples, replace
matrix.example.comwith the subdomain where tuwunel is hosted,<PORT>with the external port for federation, andexample.comwith the domain you want to use as the public-facing homeserver.
Configuration
Make sure the following are set in your configuration file or via environment variables:
- Server name: set
TUWUNEL_SERVER_NAME=example.comor in the configuration file: - Client-server URL: set
TUWUNEL_WELL_KNOWN__CLIENT=https://matrix.example.comor in the configuration file: - Server-server federation domain and port: where
<PORT>is the external port for federation (default 8448, but often 443 when reverse proxying), setTUWUNEL_WELL_KNOWN__SERVER=matrix.example.com:<PORT>or in the configuration file:
Serving .well-known endpoints
With the above configuration, tuwunel will generate and serve the appropriate /.well-known/matrix entries for delegation, so these can be served by reverse proxying /.well-known/matrix on example.com to tuwunel. Alternatively, if example.com is not behind a reverse proxy, static JSON files can be served directly.
Option 1: Static JSON files
At a minimum, the following JSON files should be created:
- At
example.com/.well-known/matrix/client:{ "m.homeserver": { "base_url": "https://matrix.example.com/" } } - At
example.com/.well-known/matrix/server(substituting<PORT>as above):{ "m.server": "matrix.example.com:<PORT>" // e.g. "matrix.example.com:443" }
Option 2: Reverse proxy
These are example configurations if example.com is reverse-proxied behind Nginx or Caddy.
Note
Replace
tuwunelwith the URL where tuwunel is listening; this may look like127.0.0.1:8008,matrix.example.com, ortuwunelif you declared anupstream tuwunelblock.
Important
These configurations need to be applied to the reverse proxy for
example.com, notmatrix.example.com.
Caddy
example.com {
reverse_proxy /.well-known/matrix/* https://matrix.example.com {
header_up Host {upstream_hostport}
}
}
Nginx
Testing
Navigate to example.com/.well-known/matrix/client and example.com/.well-known/matrix/server. These should display results similar to the JSON snippets above.
Entering example.com in the Matrix federation tester should also work.
Additional resources
For a more complete guide, see the Matrix setup with Ansible and Docker documentation on setting up .well-known.