0% found this document useful (0 votes)
128 views3 pages

Matrix Synapse-7-9

This document provides instructions for configuring Nginx as a reverse proxy for Matrix Synapse. It describes setting up Nginx virtual hosts and locations to proxy requests to Synapse and serve well-known URLs for provisioning clients. It also recommends migrating from SQLite to PostgreSQL for the Synapse database and setting up a firewall and new Matrix user for testing.

Uploaded by

Andrey Quesada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views3 pages

Matrix Synapse-7-9

This document provides instructions for configuring Nginx as a reverse proxy for Matrix Synapse. It describes setting up Nginx virtual hosts and locations to proxy requests to Synapse and serve well-known URLs for provisioning clients. It also recommends migrating from SQLite to PostgreSQL for the Synapse database and setting up a firewall and new Matrix user for testing.

Uploaded by

Andrey Quesada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3/11/2020 Matrix Synapse [NaWiki]

root /var/www/html;
index index.html index.htm;

location /_matrix {
proxy_pass http://127.0.0.1:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /.well-known/matrix/server {
return 200 '{"m.server": "example.com:443"}';
add_header Content-Type application/json;
}
location /.well-known/matrix/client {
return 200 '{"m.homeserver": {"base_url": "https://example.com"},"m.identity_serv
add_header Content-Type application/json;
add_header "Access-Control-Allow-Origin" *;
}
}

location ~ ^/.well-known/matrix/client$ { might need to escape the . Check


it!

Same for location ~ ^/.well-known/matrix/server$ { ?

Save and exit.

Activate the virtual host file and test the configuration.

sudo ln -s /etc/nginx/sites-available/matrix /etc/nginx/sites-enabled/

sudo nginx -t

If everything is fine, you should see the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok


nginx: configuration file /etc/nginx/nginx.conf test is successful

Make sure there is no error, then restart the Nginx services.

sudo systemctl restart nginx.service

Nginx installation and configuration as a reverse proxy for the Synapse homeserver has been completed.

(Optional) Step 6 - PostgreSQL instead of sqlite


https://www.natrius.eu/dokuwiki/doku.php?id=digital:server:matrixsynapse 7/13
3/11/2020 Matrix Synapse [NaWiki]

While the step is marked as optional, it is strongly encouraged for any server that isn't purely for testing.

Initial PostgreSQL setup

sudo apt install postgresql

sudo -i -u postgres

psql

postgres=# CREATE USER "username" WITH PASSWORD 'password';

postgres=# CREATE DATABASE synapse ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template

Where username can be synapse_user , and password is a new strong password you set for postgresql.

To end the postgre line just type in \q and close the postegre-usershell with exit

Set up PostgreSQL for Synapse

sudo apt install python3-psycopg2

Afterwards edit in the homeserver.yaml the database section

sudoedit /etc/matrix-synapse/homeserver.yaml

database:
name: psycopg2
args:
user: <user>
password: <pass>
database: <db>
host: <host>
cp_min: 5
cp_max: 10

user is in this case synapse_user


Database should be the above created db, example “databse: synpase”

https://www.natrius.eu/dokuwiki/doku.php?id=digital:server:matrixsynapse 8/13
3/11/2020 Matrix Synapse [NaWiki]

Host is the postgre hostname, usally /var/run/postgresql/ or 127.0.0.1

Now restart the Synapse services.

sudo systemctl restart matrix-synapse.service

Migrating from SQlite to PostgreSQL


There is no need for this if you have nothing done yet with synapse, otherwise, please refer to
https://github.com/matrix-org/synapse/blob/master/docs/postgres.rst

Step 7 - Setup UFW Firewall


Open the needed ports for our services. We will only allow SSH, HTTP, HTTPS and 8448 (for federation)
connection on the UFW firewall configuration. To add them to the UFW firewall configuration, run the
following commands.

sudo ufw allow ssh


sudo ufw allow http
sudo ufw allow https
sudo ufw allow 8448

Now enable the UFW firewall service and then check the status.

sudo ufw enable


sudo ufw status

Step 8 - Create a New Matrix User


At this stage, the Synapse homeserver installation and configuration is complete. And in this step, we need
to add a new matrix user from the command line on the server. To create a new matrix user, run the
command below.

register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml http://localhost:8008

Now you need to input the user name, password, and decide whether the user will have the admin
privileges or not. And we have created a new matrix user with admin privilege.

Step 9 - Testing

https://www.natrius.eu/dokuwiki/doku.php?id=digital:server:matrixsynapse 9/13

You might also like