Putting Synapse behind nginx, Caddy or HAProxy

A reverse proxy is the public face of a Synapse homeserver, so its routes, headers, upload limits and admin restrictions decide whether clients, federation and operators work safely. This page explains what to configure and what to confirm.

On this page

Why your Synapse reverse proxy decides whether clients and federation work

A reverse proxy sits between Synapse and everything that reaches it, so its configuration decides which Matrix traffic arrives and how it is interpreted. Synapse serves the client-server API that Element and other clients use, the server-server federation API that other homeservers use, the media endpoints for uploads and downloads, and the /_synapse/admin API for operators. Each of these paths has different expectations for timeouts, body sizes and headers, and the proxy must route them separately. If you expose Synapse to users or to other servers, you almost always need a proxy in front, typically for TLS termination, certificate renewal and routing several hostnames to one machine. Synapse can listen on its own port without one, which is workable for a lab or a single internal host, but production deployments usually want the proxy handling public connections.

The main decision is which proxy you run. nginx, Caddy and HAProxy can all front Synapse, and the Synapse reverse proxy documentation includes examples for them. nginx and HAProxy use explicit server and location or frontend and backend blocks that you write and test yourself. Caddy uses a shorter site configuration and manages certificates automatically, which reduces moving parts but still needs the same path and header rules. Whichever you choose, confirm that your team can read and change its configuration during an incident and that the proxy's own upgrade and certificate process fits your patch cycle. Also confirm the federation port you will use: Synapse federates on port 8448 by default, and delegation can move that traffic to port 443 for the server name users see. Settle that before you write routing rules, because it changes which listeners the proxy must expose.

How client, federation and admin requests reach Synapse

The diagram starts with clients and remote servers arriving at the public reverse proxy on port 443, with federation traffic on port 8448 if you use that port. The proxy forwards client, media and federation paths to Synapse's internal listener, and forwards the original client address and protocol in forwarded headers. Synapse talks to PostgreSQL on the internal side. The /_synapse/admin path is not forwarded to the internet and stays reachable only from administrator networks. Check that every admin route returns an error from a public address.

Public proxy zone and internal listener, with the admin path limited to administrator networks.

nginx, Caddy or HAProxy: which proxy fits which team

This table compares nginx, Caddy and HAProxy on the points that matter when they front Synapse: body size limits, forwarded headers, HTTP/1.1 to the upstream, the federation port and team skills. Read each row as a question to answer in your own environment, then confirm version-specific behavior against the reverse proxy docs before you commit.

Point to comparenginxCaddyHAProxy
Body size limit for uploadsSet client_max_body_size, since the default of 1M is below Synapse's 50M max_upload_size defaultSet a request body limit in the site block; confirm the directive and value for your Caddy versionEnforce limits in the frontend with tune or http-request rules; confirm the exact option against your HAProxy version
Forwarded headers to SynapsePass X-Forwarded-For, X-Forwarded-Proto and Host explicitly in the proxy location blockForwards common headers by default; confirm the headers Synapse expects in its listener settingsAdd X-Forwarded-For and related headers with http-request set-header; Synapse must be told to trust them
HTTP/1.1 to the upstreamSet proxy_http_version 1.1 so chunked responses stream correctlyNegotiates HTTP/1.1 with the upstream by default; confirm behavior for your transport settingsUse mode http with an HTTP/1.1 backend; confirm keep-alive and chunked handling in your build
Federation port 8448Add a separate server block or listen directive for 8448 if you do not use delegation to port 443Add a second site address for port 8448 or use delegation; confirm the TLS setup for that portAdd a frontend bound to 8448 with its own certificate handling and backend routing
Keeping /_synapse/admin privateRestrict the location with allow and deny, or return 404 for the path from the internetUse a matcher with respond or abort for the admin path; confirm the matcher syntaxRoute the path to a deny rule with http-request deny for external sources
Certificate handlingCertificates are managed by you or a tool such as certbot; renewal is part of your processObtains and renews public certificates automatically for public namesCertificates are loaded from files or a directory; renewal is part of your process
Team skills and toolingCommon in many operations teams with existing configuration managementSimple to read and run for small teams; less common in large enterprise standard stacksCommon where teams already run load balancers and need strict traffic control
Confirm before you commitTest the upload limit, header trust and admin block with your Synapse versionTest the same three items and the 8448 listener on your domainTest the same three items and confirm the HTTP mode on your build

How to configure the proxy routes for Synapse

This sequence takes a Synapse listener from a bare process to a reverse proxy that serves client, media and federation traffic, passes real client addresses through, accepts uploads at the configured size, and keeps the admin API off the public internet.

  1. Choose the listener layout and federation port

    Decide whether federation will run on port 443 through .well-known delegation or on port 8448 directly. Delegation lets user IDs such as @user:example.com be served from a host like matrix.example.com on 443, while Synapse federates on 8448 by default if you do not delegate. Record the chosen layout in writing, along with the Synapse listener port and bind address the proxy will forward to. Confirm the choice against your server name and delegation plan before editing any proxy file. Done when the team has one agreed diagram showing which hostname and port serves clients, media, federation and admin traffic.

  2. Forward client, media and federation paths

    Create proxy locations for the client API under /_matrix and /_synapse/client, the media API under /_matrix/media, and the federation API under /_matrix/federation on the listener you chose. Point each location at the Synapse listener over HTTP, typically on localhost. If federation uses port 8448, add a separate server block on that port with TLS. Check the syntax with the proxy's configuration test command, such as nginx -t, caddy validate or haproxy -c, and then fetch /_matrix/client/versions through the proxy. A JSON response listing supported versions confirms the client path reaches Synapse.

  3. Set forwarded headers and client IP handling

    Pass Host, X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host to the upstream so Synapse can see the original client address and scheme. In Synapse, the x_forwarded setting must be enabled on the listener that receives proxied traffic, and it should only be enabled when the proxy is the only path to that listener. For Apache, the reverse proxy docs call for nocanon and ProxyPreserveHost to be on. Confirm the result by logging in or making a request through the proxy and checking that Synapse's access log shows the client address rather than the proxy's address.

  4. Raise the body size limit to match uploads

    nginx defaults client_max_body_size to 1M, which is far below Synapse's max_upload_size default of 50M, so media uploads fail with a 413 error until you raise the limit. Set client_max_body_size on the media location or server block to match the max_upload_size value in homeserver.yaml, and use the same value on any other proxy in front. Reload the proxy, then upload a file slightly below the configured limit and one slightly above it. The first should succeed and the second should return a clear size error, which confirms both ends agree.

  5. Use HTTP/1.1 to the upstream for chunked responses

    Configure the proxy to speak HTTP/1.1 to the Synapse upstream, and clear the Connection header so keep-alive and chunked transfer work correctly. Some long-running sync and media responses are streamed in chunks, and an HTTP/1.0 upstream connection can break them. In nginx this means proxy_http_version 1.1 and a cleared Connection header in the relevant locations. Verify by requesting a long sync with a timeout through the proxy and confirming the response completes without truncation or proxy errors in the error log.

  6. Block the admin API from public routes

    Do not forward /_synapse/admin through the public listener. Return a 404 or deny response for that path on every public hostname and port, and restrict any admin access to an internal network, a VPN or a jump host that reaches Synapse directly. The Synapse configuration manual also recommends firewalling the federation listener when it is not needed by peers. Verify by requesting /_synapse/admin/v1/server_version from outside your network through the public hostname and confirming it is refused, then requesting it from the internal path and confirming a valid response.

  7. Confirm end-to-end behavior and log review

    Run a final pass with a Matrix client through the public hostname: log in, send a message, join a public room, upload a file and, if federation is enabled, check the federation tester or a request from a peer server. Review the proxy access and error logs for 413, 502 and 504 responses that point to limits or upstream problems. Record the configuration files and the test results so the next upgrade or proxy change can be repeated and checked against the same list. Done when every path in the layout works and the admin check fails from outside.

Proxy-specific settings to get right

nginx is the most common choice in Synapse documentation, and its defaults trip up installs more than anything else. Its request body limit starts at 1M, far below Synapse's default upload limit, so uploads fail with a generic error unless the proxy is adjusted. The settings below belong in the server block that serves your Matrix hostname, and the exact directive names should be checked against the current reverse proxy page before you deploy.

  • Body size: Set client_max_body_size to match max_upload_size in Synapse, which defaults to 50M. Raise both together, or the proxy becomes the limit users hit first.
  • Header forwarding: Pass Host, X-Forwarded-For and X-Forwarded-Proto with proxy_set_header, and keep x_forwarded: true in the Synapse listener so client IP addresses appear correctly in logs and rate limits.
  • Upstream protocol: Set proxy_http_version 1.1 so chunked responses from Synapse pass through intact.
  • Path matching: Forward /_matrix and /_synapse/client to the Synapse listener, and use separate server blocks if you publish federation on port 8448.
  • Admin block: Return a 404 or deny access for /_synapse/admin in a location block, so the admin API is never reachable from the public side of the proxy.

After any change, confirm that a large media upload succeeds and that /_synapse/admin returns an error from an outside network.

Keeping the admin API and internal listeners off the internet

Synapse exposes more than client traffic. The admin API, replication and metrics listeners, and the federation port all need a decision about who can reach them. The cards below cover what to block at the proxy, what to firewall at the host, and what to test before go-live.

Block the admin API at the proxy

Synapse serves its admin API under /_synapse/admin, and it can change users, rooms and media. Your proxy should return a refusal for that path to any client on the public internet, then allow it only from an internal network or VPN address. Check this with an external request to the path after every proxy change, because a catch-all location block can quietly expose it again.

Reverse proxy docs

Firewall the federation listener

Synapse federates on port 8448 by default. If you limit federation with federation_domain_whitelist, an empty list disables federation entirely, and the Synapse docs recommend firewalling the federation listener as well. Confirm that the host firewall, not only the proxy, blocks 8448 from networks you do not federate with, and test that a closed port actually refuses connections.

Configuration manual

Keep replication and metrics private

Worker deployments add replication listeners, and Synapse can expose metrics endpoints. These carry internal traffic and operational detail, so they should bind to private addresses and never be forwarded by the proxy. Review each listeners entry in your configuration, confirm its bind address, and make sure your proxy routes only the client, federation and well-known paths you intend to publish.

Workers docs

Trust forwarded client addresses only from the proxy

Behind a proxy, Synapse sees the proxy's address unless it reads the forwarded headers. Set x_forwarded on the listener so Synapse trusts X-Forwarded-For from the proxy. Because any client can send that header, the listener must not accept direct connections from the internet, or an attacker can spoof the address that Synapse logs and uses for rate limiting.

Test WAF and ModSecurity rules

Web application firewalls and ModSecurity rule sets can block the request patterns Matrix clients and federation send, including large JSON bodies and media uploads. The Synapse reverse proxy docs report that mod_security2 is incompatible with Synapse. If your security team requires a WAF, plan a test run of sync, login, media upload and federation with the rules enabled, and document each exception you add.

Proxy requirements

Questions teams ask before configuring Synapse behind a proxy

Can our own team configure Synapse behind a reverse proxy without outside help?

Yes, if your team already runs nginx, Caddy or HAProxy in front of other services and can manage TLS certificates and DNS. The Synapse side is a short list of routes, headers and size limits, and the reverse proxy guide in the Synapse documentation covers the paths that must reach the homeserver. The effort rises when your proxy estate is unusual, when you run several listeners or workers, or when you also need Matrix Authentication Service routes and separate federation endpoints. Ask yourself whether someone on the team has already tested a proxy change against a live Matrix client and a federation tester.

What drives the effort of a Synapse reverse proxy setup?

Four factors shape most of the work:

  • Existing proxy estate: a proxy you already operate, with monitoring and config management, is cheaper to extend than a new one.
  • Federation policy: whether you serve federation on port 8448, delegate to port 443, or disable federation changes which listeners and firewall rules you write.
  • Number of listeners and workers: each listener type and worker route adds a path to test and a place where requests can go to the wrong process.
  • TLS setup: certificate issuance, renewal and where TLS terminates all affect how headers reach Synapse.

For the scope and cost of your own case, ask a provider to list each of these factors in a written scope.

What do we need to provide before the proxy work starts?

Prepare these items before anyone edits a proxy configuration:

  • DNS records for the Synapse host and any delegated names, pointing at the proxy.
  • Certificates that cover every hostname the proxy serves, with a renewal method you control.
  • Network access from the proxy to the Synapse listeners and, for federation, a firewall rule that matches your federation policy.
  • A test account on the homeserver, plus a second test client, so you can check login, sync, media upload and room join after each change.

Keep a copy of your current proxy configuration so you can roll back quickly.

Is Caddy or nginx easier to use in front of Synapse?

Caddy usually needs less configuration for TLS, because it obtains and renews certificates automatically, which removes a common source of mistakes. nginx gives finer control over body size, buffering and timeouts, and many operators already know it well, so it is often the better fit for an existing estate. Both can forward the required paths and headers. HAProxy suits teams that already use it for load balancing. Choose on the basis of what your team operates and can monitor, and confirm the exact directives against the Synapse reverse proxy documentation for the version you run.

Why do file uploads fail at 1M behind a proxy?

nginx defaults to a request body limit of 1M, while Synapse accepts uploads up to 50M by default through its max_upload_size setting. When a client sends a larger file, nginx rejects the request before it reaches Synapse, and users see a failed upload with no clear message. Set client_max_body_size in nginx to match or exceed max_upload_size in your homeserver configuration. If you change max_upload_size, change the proxy value in the same maintenance window and test with a file close to the limit.

How do we verify that the admin API is blocked from the internet?

Test the blocked path from outside your network, not from inside the proxy host. Request /_synapse/admin through the public hostname and confirm the proxy returns a refusal rather than an admin response. Repeat the test from a network that has no VPN or internal route, and check the proxy access log to confirm the request was denied. Also confirm that the admin paths are reachable only from the networks you have allowed, and that the proxy does not forward them under a different path. Record the results so an auditor or a later change can check them.

When should we ask a partner for help with the proxy?

Ask for outside help when the proxy design touches several services at once, such as MAS routes, workers, a shared ingress controller or an existing gateway that other teams depend on. It also makes sense when you need a documented test plan for a compliance review, or when a federation or upload problem persists after you have checked the headers and size limits. A written scope should name the hostnames, listeners, test cases and deliverables, and it should state who keeps the configuration after handover.

What to confirm in your environment before go-live

A reverse proxy sits between every client and your Synapse listeners, so its behavior matters as much as Synapse's own settings. The cards below list the items to verify against the documentation for your exact Synapse release and your own network before you open the service to users.

Synapse release and listener expectations

Check the header, path and listener expectations in the upgrade notes for the Synapse release you deploy, because proxy rules that worked on an earlier release can break after an upgrade. Confirm which listener serves client traffic, which serves federation, and whether any port is expected to be reached directly. Compare your listeners block with the reverse proxy documentation for that release before go-live.

Synapse upgrade notes

WAF or load balancer in front

Identify every device between the client and the proxy, including a web application firewall, a cloud load balancer or a CDN. Each layer can alter request bodies, strip headers, cap sizes or time out long syncs, and a web application firewall rule set may block Matrix request patterns. Ask the security team to document each rule that touches the Matrix hostnames and test sync, media upload and federation through the full path.

Certificates and DNS records

Confirm that the certificate covers every hostname that clients, federation peers and Element Web use, and that renewal runs without manual steps. Check that DNS for the server name and the delegated host resolves to the proxy, and that the federation port is reachable from the public internet if you federate. Verify the records and certificate chain from outside your network, not only from inside it.

Upload limits against the media policy

Compare the proxy body size limit with the media upload limit set in Synapse and with your own policy on file size. A proxy limit below the Synapse limit rejects uploads with an error that looks like a Synapse fault. Record both values in your runbook so that a future policy change updates the proxy and the homeserver together.

Synapse configuration manual

Whether workers change routing

If you run Synapse workers, the proxy must send each endpoint family to the worker type that handles it, and a single upstream may no longer be enough. Confirm the routing table against the workers documentation for your release, and check which endpoints still go to the main process. Test client sync, messaging, federation and admin paths after every change to the worker layout.

Synapse workers docs

Where proxy mistakes show up later

Proxy mistakes rarely break the first login test. They surface after launch, when real users upload files, when remote servers federate with you, and when someone reads the logs. The most common failures are large media uploads that fail with an error that looks like a Synapse problem, federation requests that time out under load, and logs that show every client as the proxy's own address, which makes rate limiting and abuse investigation unreliable. Another is an admin endpoint that answers from the public internet because a broad location rule matched a path nobody meant to expose. Each of these looks different to users, so teams often chase the wrong component first.

A route review before go-live catches most of these. Walk every location block and list the paths it forwards, the listener port it targets, and whether the path is meant for clients, federation, media or administration. Confirm that /_synapse/admin returns nothing from an outside network, and that the federation listener is reachable only where you intend it to be. Check that the proxy's body size limit matches Synapse's max_upload_size, and that the client address Synapse records comes from the forwarded headers your proxy sets, with trusted proxy addresses declared in Synapse's listener settings. Confirm these details against the current Synapse reverse proxy documentation for the version you run.

A test plan turns the review into evidence. Upload a file close to the configured limit and one just over it, and confirm the error text and the status code are what you expect. Run a federation test from a second server, and watch for timeouts during a larger room join. Make an admin request from outside your network and confirm it is refused. Finally, check the access log for a real client address on a sample login. Repeat these checks after every proxy change and after every Synapse upgrade, since route lists and default limits can change between releases. Record the results so your security and operations teams can review them without rerunning the work.

How DeployOpen scopes and delivers a Synapse proxy setup

This sequence turns an unclear proxy question into a written scope, a tested configuration on your own infrastructure, and handover documentation your team can operate after the work ends.

  1. Agree the written scope

    Before any work starts, DeployOpen and your team agree in writing which proxy product, hostnames, listeners and admin restrictions are in scope, who approves changes, and what the deliverables are. Your team confirms the Synapse version it runs and the topology it uses, such as a single process or workers. The step is complete when the scope document is signed off and the open questions about certificates, load balancers and network zones have named owners.

  2. Review the existing proxy estate

    DeployOpen reviews the proxies, load balancers and TLS terminations already in front of Synapse, including any Apache or mod_security layers that sit in the request path. The review checks which paths reach Synapse, how forwarded headers are set, the configured body size limit, and whether the federation listener on port 8448 is reachable from where it should be. The output is a short gap list that your team can accept or reject before configuration starts.

  3. Configure routes and forwarded headers

    DeployOpen writes the proxy configuration inside your infrastructure, using your certificates and your deployment tooling where you have it. Client and federation paths are forwarded to the Synapse listeners, forwarded headers are set so Synapse sees the original client address and protocol, and the body size limit is raised to match Synapse's upload setting. HTTP/1.1 is used for upstream connections so chunked responses are handled correctly. The step closes when the configuration is committed to your repository and reviewed by your team.

  4. Test client and federation routes

    DeployOpen runs requests against each forwarded path from the networks that should reach it, and from networks that should not. Checks cover client API calls, media upload at a size near the limit, long-running responses, and federation requests to the listener. Results are recorded with the expected and actual status for each route. The step is complete when every route passes or has a documented, approved exception.

  5. Verify admin path restrictions

    DeployOpen confirms that the /_synapse/admin path is not reachable from the public internet, and that it is only served to the administrative networks or identity controls your team specifies. The test is run from outside your network and from an approved admin location, and the results are kept as evidence. Any path that is reachable from the wrong place is fixed and retested before the step is marked complete.

  6. Hand over runbooks and configuration

    DeployOpen delivers the final configuration, a route map, the test scripts and results, the restriction list for admin and replication paths, and runbooks for certificate renewal, configuration changes and rollback. Your administrators walk through the runbooks, and the handover is recorded against the agreed scope. The output is a set of documents your own team can operate without DeployOpen present.

  7. Retain ongoing support if needed

    After handover, your team may keep DeployOpen on a retainer for proxy changes, Synapse upgrades that alter proxy requirements, and periodic retesting of routes and admin restrictions. The retainer scope, response expectations and fees are agreed in writing, and nothing in the retainer is required to operate the handed-over setup. Ask for the retainer terms in the quote alongside the fixed-scope proposal.

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.