Difference between revisions of "Matrix"

From Organic Design wiki
m (Troubleshooting)
(Docker installation: postgres conf in homeserver)
Line 4: Line 4:
 
First you'll need to configure your web-server as a reverse proxy from SSL ports 443 and 8448 to the internal non-SSL port 8008. This is the default Matrix port for unsecured HTTP traffic, so that a reverse proxy needs to be set up from your web-server to handle the HTTPS side of things on exposing the default Matrix HTTPS port of '''8448''' to the public that connects to the the internal HTTP port on 8008. Also there needs to be a connection from port '''443''', see the official [https://github.com/matrix-org/synapse/blob/master/docs/reverse_proxy.md reverse proxy notes] for details about the reverse proxy setup.
 
First you'll need to configure your web-server as a reverse proxy from SSL ports 443 and 8448 to the internal non-SSL port 8008. This is the default Matrix port for unsecured HTTP traffic, so that a reverse proxy needs to be set up from your web-server to handle the HTTPS side of things on exposing the default Matrix HTTPS port of '''8448''' to the public that connects to the the internal HTTP port on 8008. Also there needs to be a connection from port '''443''', see the official [https://github.com/matrix-org/synapse/blob/master/docs/reverse_proxy.md reverse proxy notes] for details about the reverse proxy setup.
  
We'll be using ''PostgreSQL'' instead of the default ''SQLite'' database, which means that we'll need to use ''docker-compose''. So first create a directory for the configuration and data and then put a ''docker-compose.yml'' file in it with the following content.
+
We'll be using ''PostgreSQL'' instead of the default ''SQLite'' database, which means that we'll need to use ''docker-compose''. So first create a directory for the configuration and data and then put a ''docker-compose.yml'' file in it with the following content which will create persistent volumes to put the ''synapse'' data in ''data/system'' and the ''PostgreSQL'' data in ''data/postgres''.
 
<source lang="yaml">
 
<source lang="yaml">
 
version: '3'
 
version: '3'
Line 71: Line 71:
 
  template=template0
 
  template=template0
 
  OWNER synapse;
 
  OWNER synapse;
 +
</source>
 +
 +
 +
Then edit the ''data/system/homeserver.yaml'' configuration and add the following to the database section. Note that the database host is ''postgres'' not ''localhost'', because it needs to be accessed via the hostname given to the database service defined in the ''docker-compose.yml'' file. The database name and database user must also match the environment given to the database service in the ''docker-compose.yml'' file.
 +
<source lang="yaml">
 +
database:
 +
  name: psycopg2
 +
  args:
 +
    user: synapse
 +
    database: synapse
 +
    host: {!postgres!}
 +
    cp_min: 5
 +
    cp_max: 10
 
</source>
 
</source>
  

Revision as of 23:04, 17 June 2020

Cone.png This article or section is a stub. Stubs are articles that have not yet received substantial attention from the authors. They are short or insufficient pieces of information and require additions to further increase the article's usefulness. The project values stubs as useful first steps toward complete articles.


Docker installation

First you'll need to configure your web-server as a reverse proxy from SSL ports 443 and 8448 to the internal non-SSL port 8008. This is the default Matrix port for unsecured HTTP traffic, so that a reverse proxy needs to be set up from your web-server to handle the HTTPS side of things on exposing the default Matrix HTTPS port of 8448 to the public that connects to the the internal HTTP port on 8008. Also there needs to be a connection from port 443, see the official reverse proxy notes for details about the reverse proxy setup.

We'll be using PostgreSQL instead of the default SQLite database, which means that we'll need to use docker-compose. So first create a directory for the configuration and data and then put a docker-compose.yml file in it with the following content which will create persistent volumes to put the synapse data in data/system and the PostgreSQL data in data/postgres.

version: '3'
services:

  postgres:
    restart: unless-stopped
    image: postgres:9.6-alpine
    environment:
      - POSTGRES_USER=synapse
      - POSTGRES_DB=synapse
    networks:
     - internal_network
    volumes:
      - ./data/postgres:/var/lib/postgresql/data

  synapse:
    image: matrixdotorg/synapse:latest
    restart: unless-stopped
    networks:
      - external_network
      - internal_network
    ports:
      - "127.0.0.1:8008:8008"
    environment:
      - SYNAPSE_SERVER_NAME=organicdesign.co.nz
      - SYNAPSE_REPORT_STATS=no
    depends_on:
      - postgres
    volumes:
      - ./data/system:/data

networks:
  external_network:
  internal_network:
    internal: true


Next, generate a default configuration file for your domain as follows. This will create a new volume with your persistent configuration file in it called homeserver.yaml as well as some keys for your domain.

docker run -it --rm -v "/FULL/PATH/TO/DIR/data/system:/data" -e SYNAPSE_SERVER_NAME=organicdesign.co.nz -e SYNAPSE_REPORT_STATS=no matrixdotorg/synapse:latest generate


Then start the container in the background.

docker-compose up -d


Now we need to create a database with the correct encoding (we may need to drop an initially created one first). So first log in to the PostgreSQL database.

docker exec -it CONTAINER-ID psql -U synapse


Connect to the postgres database so you can drop synapse, and then create a new synapse database with the correct encoding.

\connect postgres
DROP DATABASE synapse;
CREATE DATABASE synapse
 ENCODING 'UTF8'
 LC_COLLATE='C'
 LC_CTYPE='C'
 template=template0
 OWNER synapse;


Then edit the data/system/homeserver.yaml configuration and add the following to the database section. Note that the database host is postgres not localhost, because it needs to be accessed via the hostname given to the database service defined in the docker-compose.yml file. The database name and database user must also match the environment given to the database service in the docker-compose.yml file.

database:
  name: psycopg2
  args:
    user: synapse
    database: synapse
    host: postgres
    cp_min: 5
    cp_max: 10


Then exit out of PostgreSQL, restart the container and set up a user (check the logs to ensure its running):

docker-compose down
docker-compose up -d
docker exec -it CONTAINER_ID register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008

Enabling email

Synapse can use email for user password resetting and notification of missed messages.

Troubleshooting

Check https://YOURDOMAIN/_matrix/client/versions in a browser, it should respond with something like the following:

{
  "versions": ["r0.0.1", "r0.1.0", "r0.2.0", "r0.3.0", "r0.4.0", "r0.5.0"],
  "unstable_features": {
    "m.id_access_token": true,
    "m.require_identity_server": false,
    "m.separate_add_and_bind": true,
    "org.matrix.label_based_filtering": true,
    "org.matrix.e2e_cross_signing": true,
    "org.matrix.msc2432": true
  }
}


And it should have the following CORS headers:

access-control-allow-headers  Origin, X-Requested-With, Content-Type, Accept, Authorization
access-control-allow-methods  GET, POST, PUT, DELETE, OPTIONS
access-control-allow-origin   *

See also