Set up sliding sync for Matrix self-hosted instances

Adapt to Element X client by adding Sliding Sync to your self host Matrix Synapse server, with Docker Compose, Nginx reverse proxy, CloudFlare worker function.

As I am working on a brand new Discord-styled modern Matrix client, I went into an issue: because I use the newest Matrix Rust SDK, it requires Sliding Sync (as does the new Element X app). So my self-hosted test Matrix server no longer works.

I could not find any guides on how to set this up. So I am writing it here on how I did it by referencing the official documentation:

Docker compose file

For just running the sliding sync server

Remember to modify `SYNCV3_SERVER` to be your own instance’s hostname

Generate a secret code:

Start docker:

For running Matrix server with sliding sync server:

Setup Nginx

If you use Nginx for forwarding requests, you should add the below in your existing Nginx configuration file:

By the way, here is an example Nginx file for a Matrix instance:

Modify your Matrix .well-known file

It should look like this, but with all hostname replaced:

If your sliding sync proxy `org.matrix.msc3575.proxy` runs on the same server, set it to be the same as your `m.homeserver`

If you’re hosting your website on CloudFlare, you should use a CloudFlare worker to respond the well known file:

If you’re using Nginx, you should provide a custom well known file, and write the rule to read all well known requests from your given path.

Here is the example content of the client file located at `/var/www/html/.well-known/matrix/client`

Here is the example content of the server file located at `/var/www/html/.well-known/matrix/server`

Don’t forget to apply the updated configuration file:

Cheers!