Matrix .well-known delegation for server and client discovery

Serve two well-known files so user IDs keep your domain while Synapse runs on its own host, with the CORS headers browsers need.

On this page

Why Matrix .well-known delegation keeps user IDs on your domain

You want users to be @name:example.com while the Synapse process runs on matrix.example.com. The server_name you choose is the part of the ID that never changes, because it is stamped into every user ID and room ID the server creates. Delegation is what lets the hostname that serves traffic differ from that name. Two well-known files do the work. /.well-known/matrix/server tells other homeservers where to send federation traffic for example.com, and /.well-known/matrix/client tells Matrix clients which base URL to use when a user signs in with a bare domain. The server file must be reachable on port 443 of example.com itself, and its m.server value defaults to port 8448 when no port is written, so a delegation that points at matrix.example.com on port 443 must state that port explicitly.

Teams usually need delegation when their identity domain is also the company's main web domain, while the Matrix services sit on a subdomain or on a different host. It also pays off when you expect to move Synapse, MAS or Element Web later. Clients and other servers keep resolving @name:example.com while the backend changes behind the delegated name. Before you publish the files, confirm three things with your own network team: who controls the web server answering on example.com, whether that server can serve two small JSON files at fixed paths, and whether your certificates cover the hostname that appears in m.server. Those answers decide whether delegation is a few lines of web server config or a larger change.

Treat this as a decision that belongs to the wider deployment plan, not a last-minute patch. The choice of server name, subdomain layout and where the reverse proxy terminates TLS all depend on it, and changing the server name after users and rooms exist is not a routine fix. Settle the permanent name first, then decide whether delegation is needed, and record both in the design. The Synapse delegation documentation covers the exact file format and port behavior, and it is the reference to check against your final hostnames before go-live.

How to publish the server and client well-known files

This sequence sets up the two discovery files so that users keep identifiers like @name:example.com while Synapse runs on a separate host. The result is a verified server file for federation and a client file with CORS headers for browser sign-in.

  1. Confirm server name and Synapse host

    Write down the permanent server_name, the apex domain that appears after the colon in user IDs, and the host where Synapse actually listens, such as matrix.example.com. Check that the apex domain is under your control and that the Synapse host resolves publicly with a valid certificate. Ask your team to confirm which port Synapse's federation listener uses, because the server file must point to it. The step is done when you have one written record of server_name, Synapse host and federation port that every later step references.

  2. Publish the server well-known file

    On the web server that answers for the apex domain, serve /.well-known/matrix/server over HTTPS with a JSON body whose m.server value names the federation host and port, for example illustrative value matrix.example.com:8448. The file must be reachable on port 443 even though federation itself runs elsewhere. Confirm the response has a JSON content type and a valid TLS certificate for the apex domain. The step is done when a plain HTTPS request to the apex returns the JSON body with status 200.

  3. Publish the client well-known file

    Serve /.well-known/matrix/client on the same apex domain with a JSON object containing m.homeserver and a base_url field that points to the Synapse client endpoint, for example illustrative value Clients read this file to find the homeserver after a user types only their domain. If you also deploy identity or authentication services, add their entries as the Matrix client discovery documentation describes. The step is done when the file returns the expected base_url from port 443 with a JSON content type.

  4. Add CORS headers to the client file

    Return an Access-Control-Allow-Origin header on the client well-known response, commonly set to * in the Synapse installation guidance, so that browser-based clients such as Element Web can read the file from another origin. Apply the header only to the client file unless your own design requires more. Ask your security team to confirm that a wildcard origin is acceptable for a file that carries only public discovery data. The step is done when a request with an Origin header receives the Access-Control-Allow-Origin response header.

  5. Verify both files with curl

    From a machine outside your network, run curl against and /client, using illustrative values, and inspect the status code, Content-Type, certificate chain and JSON body. Repeat the request with an Origin header to confirm the CORS header appears on the client file. Check that no redirect sends the request away from port 443 or to an HTTP address. The step is done when both files return 200, valid JSON and the expected values from every external network you tested.

  6. Run a federation tester against the domain

    Use a Matrix federation tester or the federation check that the Synapse project documents to confirm that a remote server resolves your server_name to the correct host and port and that the TLS certificate is valid for that name. Review each reported error and trace it back to the server file, DNS record or certificate. Re-run after every change. The step is done when the tester reports successful federation resolution and certificate validation for your server_name.

  7. Test a browser sign-in from a clean client

    Open a browser-based Matrix client, enter only your domain, such as example.com, and confirm it discovers the homeserver without manual entry. Check the browser developer console for CORS or certificate errors. Keep a record of the files' final content and the date of the test so that future changes to the web server or certificate are reviewed against a known good state. The step is done when discovery succeeds from a fresh browser session and the console shows no discovery errors.

Delegation options compared: well-known files, SRV records and direct hostnames

This table compares serving .well-known files, publishing SRV records, and keeping Synapse on the server_name host with no delegation. Read each row for what the option covers, how much certificate work it creates, and the setups it fits. The main takeaway is that well-known delegation covers both server and client discovery with a single TLS certificate on port 443, which is why it is the usual choice.

OptionWhat it coversTLS and certificate complexityWhen it fits
Well-known files (m.server and client)Both server-to-server federation and client discoveryCertificate on the web host serving the files, plus one on the Synapse host if it is separate. Files must be reachable on port 443Default choice when Synapse runs on a host such as matrix.example.com but user IDs should stay @name:example.com
SRV recordsServer-to-server federation onlyHarder to get right, because the certificate must match the target host that the SRV record points to. Browsers and clients still need another discovery methodRarely needed. Use only when you have a specific reason to avoid serving a file on port 443 and can test the TLS chain carefully
Direct hostname (no delegation)Both, when server_name is the host Synapse servesSimplest. One certificate covers the server name, and federation uses port 8448 unless you change the listenerFits a new deployment where the server_name host and the Synapse host are the same and no later move is planned
Well-known files with a separate Synapse hostBoth, with the m.server value pointing at the Synapse hostTwo hostnames to certify. Confirm the m.server value and certificate names match before you test federationCommon for production layouts where the Synapse service can move without changing user IDs
Client discovery only (client well-known file)Client discovery for browsers and apps, not federationNeeds CORS headers such as Access-Control-Allow-Origin on the client file, or browser clients may failUse alongside a server file when clients must find the homeserver from the bare domain

Where browsers and federation peers fail

Delegation problems rarely show up as a single clear error. A user sees a login screen that never completes, or a remote server silently refuses to federate, and the cause sits in one of two small files served from the bare domain. The cards below cover the faults that most often break discovery, and how to check each one from outside your network.

Missing CORS header on the client file

Browser-based clients such as Element Web fetch /.well-known/matrix/client from the bare domain before they know which homeserver to use. If that response lacks an Access-Control-Allow-Origin header, the browser blocks the read and the login page reports that no homeserver was found, even though the server itself is healthy. Check it with a browser developer tools network tab or with curl, looking for the header on the client file specifically.

Installation docs

Port 443 not reachable

The well-known files must be served over HTTPS on port 443 of the bare domain, while federation itself uses port 8448 unless the m.server value names another port. A firewall, load balancer or DNS record that sends the bare domain somewhere other than your web server will fail discovery without any Matrix error in the logs. Confirm that the bare domain resolves to the host serving the files and that port 443 answers from outside your network.

Certificate mismatch on the federation host

Remote servers follow the m.server value to the named host and verify its TLS certificate against that host name. If the certificate covers only the bare domain, or has expired, peers reject the connection even when the well-known file is correct. Inspect the certificate presented on the target host and port with an external TLS checker, and confirm the name matches the host given in m.server.

Server file points to a host without valid TLS

The m.server value can name a host that exists in DNS but has no working listener, a self-signed certificate, or a proxy that does not route federation paths. Remote servers then fail after they have already read the file, which makes the fault look like a remote problem. Verify the named host end to end, including the federation version endpoint, before changing the delegation file itself.

Redirects and caching on well-known responses

Both files should answer directly with status 200 and a JSON body. A redirect from the bare domain to a web application, or a CDN or proxy cache that holds an old copy after a homeserver move, sends clients and peers to a stale or wrong target. Use curl without following redirects to confirm that the first response is the file itself, and check cache headers after any change.

How a client and a remote server find your homeserver

Discovery starts with two requests to the public web host for example.com, which is the domain users see in their Matrix IDs. A client reads the base URL from /.well-known/matrix/client and then talks to the homeserver behind matrix.example.com. A remote server reads m.server from /.well-known/matrix/server and connects to the delegated host, where federation normally listens on port 8448 unless a port is given. Check that both files return valid JSON on port 443 and that the client file sends CORS headers, since browsers will refuse it without them.

Discovery files on the public host point clients and remote servers at the homeserver.

When to delegate and when to keep the hostname simple

The choice is between two layouts. If the homeserver runs on the apex domain, such as example.com, user IDs like @name:example.com need no delegation file at all, and clients and remote servers find the server directly on port 8448 for federation. If Synapse runs on a subdomain such as matrix.example.com while the identity stays at example.com, you must serve /.well-known/matrix/server from the apex, and that file tells other servers where to send federation traffic. Delegation costs one extra file on a domain you may already run for email, a website or other services, but it lets the homeserver move to a new host later without changing a single user ID. Confirm which hostname you will use before you commit, because user IDs and room identifiers cannot be renamed afterward.

The apex web server becomes part of the trust chain once delegation is in place. Whoever controls the content served at the apex can redirect federation for every user on the domain, so the apex host needs the same change control, access logging and TLS care as the homeserver itself. Check who holds deployment rights on that web server, whether it is shared with a marketing or hosting team, and whether a compromise there would be detected. Also confirm the exact m.server value you will publish, since it must match a host and port that Synapse actually answers on. The Synapse delegation documentation describes the file format and the checks to run after publishing it.

Make this decision as part of the permanent server_name decision in your domain layout, not as a separate convenience setting. If the organization expects to rehost Synapse, add MAS, or move Element Web to another domain within the next few years, delegation keeps user IDs stable through those moves, and the apex file is the one place that changes. If the homeserver is small, fixed and never expected to move, keeping the hostname simple avoids a file on the apex and removes one component from the review. Document the decision with the people who will own the apex domain, so that a later change to DNS or the web server does not silently break federation.

Security and operational considerations for discovery files

The two well-known files sit on the apex domain, outside the Synapse host, so they often escape the controls that cover the homeserver itself. The cards below cover the places where a small change to discovery can break logins, federation, or the scope you intended to allow.

Put the apex web server under DNS change control

The apex domain serves the discovery files that every other server and client reads first, yet it is often managed by the web or marketing team. Treat a change to that web server with the same review as a DNS change: who approves it, who can deploy it, and how it is rolled back. Check that the apex host's configuration lists the well-known paths explicitly, so a redesign or redirect rule does not silently remove them.

Renew certificates on both hosts

Discovery depends on two certificates: the one for the apex domain that serves /.well-known/matrix/server and /.well-known/matrix/client, and the one on the federation host that the delegated m.server value points to. A renewal that succeeds on one host and fails on the other breaks federation while the apex still looks healthy. Confirm that both renewals are automated, that expiry alerts reach a team that acts on them, and that each certificate covers the exact name it serves.

Monitor both well-known URLs

Add uptime checks for /.well-known/matrix/server and /.well-known/matrix/client in addition to the homeserver health endpoint. Each check should confirm the HTTP status, the JSON body, and the CORS header on the client file, since a file that returns the right body with the header missing still breaks browser sign-in. Run the checks from outside your network, because an internal check can pass while the public path is broken.

Keep the admin API off discovery

Discovery files are public by design, so they should advertise only the federation endpoint and, for clients, the base URL of the homeserver. Do not add the admin API, the replication listener, or internal hostnames to the JSON. Confirm that the reverse proxy routes /_synapse/admin to nothing public, and that any administrative hostname is not listed in either file.

Align federation scope with the files

The federation_domain_whitelist setting controls which domains your server federates with, and an empty list disables federation. A discovery file that advertises a federation endpoint invites other servers to connect, so the two must agree. Before publishing or changing the files, confirm the whitelist matches your intended scope, and firewall the federation listener as the Synapse documentation recommends so that the advertised endpoint is not the only control.

Synapse configuration manual

Questions teams ask before delegating Matrix discovery

Can our own team set up Matrix .well-known delegation without a partner?

Yes, in most environments a team with DNS and web server access can publish the two well-known files themselves. The work is small in file terms: one JSON document that points federation traffic at the host serving Synapse on port 443 or 8448, and one client document that names your homeserver base URL and sends CORS headers. The effort comes from access and verification, not from the JSON. Your team needs to control the web server behind your server name domain, be able to serve the files over HTTPS with a valid certificate, and test federation and client login afterward. If any of those belong to different teams, the coordination is usually what takes time.

What drives the effort of setting up Matrix discovery?

The main drivers are DNS access, web server control, certificate setup and the number of hosts involved. Effort rises when DNS changes go through a separate change process, when the domain that serves the well-known files is run by someone else, or when the homeserver sits behind several proxies that each need the right routes. Certificate setup adds work when the certificate for the server name domain must cover the host that serves the files. The number of hosts matters too: a single Synapse host behind one proxy is simpler than a split layout with Element Web, MAS and the homeserver on separate names. Ask the person quoting to list each system touched.

Does Matrix discovery need ongoing work after it is set up?

Most of the work is one-time, but some parts recur. Certificates on the host that serves the well-known files must renew, and a renewal failure can break federation or client discovery without any change to Synapse itself. Changes to the homeserver host, its port or its name also require updating the delegation files, and the files should be checked after any proxy or ingress change. Keep a note of who owns the DNS records and the web server so that changes made during a Synapse upgrade or a move to a new cluster do not leave stale delegation behind.

What should we ask a partner for in a fixed-scope quote?

Ask for a written list of the systems in scope, including the DNS zones, the web servers that will host the two well-known files, the certificate method, and the homeserver hosts. Ask which files will be delivered, how the client document will be tested from a browser with CORS headers, and how federation will be verified with an external federation tester. Confirm what is excluded, such as changes to Synapse configuration, reverse proxy rules for other paths, or DNS changes you must make yourselves. Ask for the handover format, the test evidence and the process for changes after delivery. A quote that states these items is easier to compare with an internal plan.

Is SRV delegation a better option than well-known files?

Usually not. SRV delegation is possible, but it is generally discouraged because TLS certificates are harder to get right, and it covers only server-to-server traffic. Serving the m.server value in a well-known file keeps federation and the client discovery document in one place, and it lets you set the port explicitly. Client discovery also needs the well-known client file regardless, so SRV does not remove that work. Teams that already run SRV records for other services may still choose it, but they should confirm certificate handling for the target host and plan separate client discovery. The Synapse delegation documentation explains the trade-offs in more detail.

Which parts of the delegation work carry the most risk if they go wrong?

The highest risk sits in the TLS certificate and the file contents. If the certificate on the host serving the well-known file is invalid, federation can fail silently for remote servers while local users still log in. An incorrect m.server value can send federation to the wrong port or host. A missing CORS header stops browser clients from discovering the homeserver, which looks like a login problem to users. Test both files from outside your network, check the certificate chain, and confirm that browser login works from your Element Web origin before users depend on the setup.

Will a homeserver move break existing user IDs?

No, a correct delegation lets user IDs such as @name:example.com stay the same while Synapse runs on a different host, such as matrix.example.com. The server_name stays fixed, and only the delegation files and DNS change. Moving the server_name itself is a different matter, because it is part of every user and room identifier. Confirm the permanent server name before you publish any files, and ask any partner to confirm the plan for changing the host behind it, including how existing federation peers will reach the new location.

How discovery fits the wider Matrix deployment plan

Delegation cannot be planned on its own. The .well-known files publish a decision that was already made elsewhere: which host name carries the permanent server_name, where Synapse listens, and how TLS terminates. If the server_name changes later, every user ID and room identifier built on it changes with it, so the choice belongs in the deployment plan first. The delegation files then point federation and client traffic at the host that runs the homeserver, usually on port 443 for the well-known responses and port 8448 or 443 for federation, depending on how the proxy is set up. Scope the delegation work together with the server name decision, the reverse proxy routes and the certificate plan, because a mismatch in any one of them shows up as failed federation or failed client sign-in that is hard to trace back to its cause.

The reverse proxy is where most of the coupling sits. The same web server or ingress that serves the homeserver must also return the /.well-known/matrix/server and /.well-known/matrix/client responses on the bare domain, with the correct content type and the CORS headers that browser clients require. Confirm early which host serves the bare domain today, whether a website or another service already owns it, and who controls that configuration. If Element Web, Matrix Authentication Service or ESS components are placed on their own subdomains, the client well-known response must name the right homeserver base URL for each of them. Write these routes into the same change record as the proxy and certificate work so that one review covers all of them.

The TLS certificate must cover every name a client or remote server will contact during discovery, and renewal must reach the proxy that serves those names. Ask who issues and renews the certificate for the bare domain and the homeserver host, and test renewal before go-live rather than after the first expiry. Federation has its own failure modes that appear only between servers, so plan a check from outside your network, not only from inside it. Where the deployment is air-gapped or federation is restricted, the delegation files still matter for the internal clients, but the federation allow list changes what they are meant to achieve. Decide these questions as one design, and keep a single owner accountable for the server name, the delegation files and the certificates.

How DeployOpen scopes and delivers Matrix discovery work

DeployOpen plans, builds and documents the .well-known delegation for a Matrix homeserver inside infrastructure the client controls, so user IDs keep the organization's domain while Synapse runs on its own host. Each engagement starts from a written scope and ends with files, checks and notes the client's own team can operate.

How we scope

  • Confirm the permanent server_name and the host that will serve Synapse before any file is written.
  • Record which hosts serve the server and client well-known files, and who controls DNS and web servers for each.
  • Agree in writing whether engagements are fixed-scope and whether ongoing support is needed as a retainer.

How we build

  • Write the server well-known file with the correct federation host and port, and confirm it is served on port 443.
  • Write the client well-known file with the homeserver base URL and add the CORS headers browser clients require.
  • Test each endpoint from outside the network and from a browser origin, then record the results for review.

How we hand over

  • Deliver the file contents, web server configuration and DNS changes as documented, version-controlled artifacts.
  • Document the decision to use well-known over SRV records, including the TLS and server-to-server trade-offs for your setup.
  • Walk through the verification steps and the change process so your team can repeat them after certificate or host changes.

How we support

  • Retest delegation after Synapse, reverse proxy or certificate changes as part of an agreed support scope.
  • Review discovery behavior when a homeserver moves host, port or domain, and update the documented configuration.
  • Offer continuous testing and upgrades as retainers, with scope and frequency agreed in writing before work starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.