Install Synapse Matrix server on Ubuntu 20.04.3


apt update
apt install python3 nginx certbot vim
docker run -it --rm \
  --mount type=volume,src=synapse-data,dst=/data \
  matrixdotorg/synapse:latest generate



Config will be located at:

Recommend you review settings.


certbot --nginx -d YOURDOMAIN -d matrix.YOURDOMAIN

Then ensure it gets automatically renewed

crotab -e

Add the line:

0 12 * * * /usr/bin/certbot renew --quiet


Remove the default server configuration in /etc/nginx/sites-enabled/default and replace with


    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # For the federation port -> remove if you don't want to enable federation
    listen 8448 ssl http2 default_server;
    listen [::]:8448 ssl http2 default_server;

    server_name matrix.YOURDOMAIN;

  location ~ ^(/_matrix|/_synapse/client)
      # note: do not add a path (even a single /) after the port in `proxy_pass`,
      # otherwise nginx will canonicalise the URI and cause signature verification
      # errors.
      proxy_pass http://localhost:8008;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $host;

      # Nginx by default only allows file uploads up to 1M in size
      # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
      client_max_body_size 50M;

Then restart Nginx

nginx -t && nginx -s reload


docker run -d --name synapse --mount type=volume,src=synapse-data,dst=/data \
  -p 8008:8008 matrixdotorg/synapse:latest

Check running

apt install lynx
lynx http://localhost:8008

Create user accounts

docker exec -it synapse register_new_matrix_user -c \
  -k "your-secret-key-in-homeserver.yaml" http://localhost:8008


DNS SRV and .well-known to point DOMAIN -> matrix.DOMAIN


docker pull matrixdotorg/synapse:latest
root@localhost:~# docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS                  PORTS                                                           NAMES
a06e8a24d1a6   1776cc2e846d   "/"   4 months ago   Up 4 months (healthy)   8009/tcp,>8008/tcp, :::8008->8008/tcp, 8448/tcp   synapse
docker stop a06e8a24d1a6
docker rm a06e8a24d1a6
docker run -d --name synapse --mount type=volume,src=synapse-data,dst=/data   -p 8008:8008 matrixdotorg/synapse:latest