Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| services:synapse [2025/01/31 14:23] – [Matrix - Synapse] willy | services:synapse [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Matrix - Synapse | ||
| - | |||
| - | **Note:** i migrated to [[services: | ||
| - | |||
| - | [[https:// | ||
| - | |||
| - | It looks amazing and it already has so many features that can replace other proprietary solutions. Unfortunately, | ||
| - | |||
| - | The Telegram integration works pretty well, even if the initial setup proved to be a bit shaky, it's solid after that phase. I didnt explore any other bridge at the moment. | ||
| - | |||
| - | Overall i am not yet sure if the effort is worthwile, but since i believe in the need for an open internet, i will give Matrix more time. | ||
| - | |||
| - | ===== Tools and Architecture ===== | ||
| - | |||
| - | Matrix is the high-level protocol. To join, or host, a Matrix network you need a Matrix server implementation. There are quite a few but i choose [[https:// | ||
| - | |||
| - | In addition to the server itself, you need the bridges if you want to connect your matrix instance to other messaging platforms. I only use Telegram and Whatsapp (well, discord maybe, but it's more of a forum for me than an actual messaging tool), and of these only Telegram has a viable bridge. | ||
| - | |||
| - | More info about the bridges can be found [[https:// | ||
| - | |||
| - | To use Matrix properly you **do need** one dedicated subdomain. It is teorically possible to host on sub-paths, but i do not recomend it as it adds another layer of uncertainity and complexity that you don't want. I will assume you have **https:// | ||
| - | |||
| - | ===== Installation ===== | ||
| - | |||
| - | It is possible to install Synapse and the Telegram bridge on bare-metal leveraging Python Virtual Envs, but unless you want to use a SQLite (which won't scale easily) database, you will also need a PostgresSQL installation. | ||
| - | |||
| - | Overall, i prefer to go the container route which proved to be easy enough. Setting up and running properly your Matrix instance is already tricky that adding a bare-metal installation hurdle didnt seems needed. | ||
| - | |||
| - | As usual create one dedicated user, and create a data folder where all the data will be stored: | ||
| - | <code bash> | ||
| - | useradd -d / | ||
| - | mkdir / | ||
| - | mkdir / | ||
| - | mkdir / | ||
| - | mkdir / | ||
| - | mkdir / | ||
| - | chown synapse: | ||
| - | </ | ||
| - | |||
| - | The **data** folder will contain Synapse configuration and uploaded files. The **database** folder will contain the PostgreSQL database. The **bridges** folders will contain each one bridge various files. | ||
| - | |||
| - | Now, take the following **docker-compose.yml** file and adapt to your needs: | ||
| - | <file - docker-composer.yml> | ||
| - | version: ' | ||
| - | services: | ||
| - | synapse: | ||
| - | image: docker.io/ | ||
| - | restart: unless-stopped | ||
| - | environment: | ||
| - | - SYNAPSE_CONFIG_PATH=/ | ||
| - | volumes: | ||
| - | - / | ||
| - | depends_on: | ||
| - | - db | ||
| - | ports: | ||
| - | - 8008: | ||
| - | networks: | ||
| - | - synapse-net | ||
| - | |||
| - | mautrix-telegram: | ||
| - | container_name: | ||
| - | image: dock.mau.dev/ | ||
| - | restart: unless-stopped | ||
| - | depends_on: | ||
| - | - db | ||
| - | volumes: | ||
| - | - / | ||
| - | networks: | ||
| - | - synapse-net | ||
| - | db: | ||
| - | image: docker.io/ | ||
| - | # Change that password, of course! | ||
| - | environment: | ||
| - | - POSTGRES_USER=synapse | ||
| - | - POSTGRES_PASSWORD=<<< | ||
| - | - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C | ||
| - | volumes: | ||
| - | - / | ||
| - | networks: | ||
| - | - synapse-net | ||
| - | |||
| - | networks: | ||
| - | synapse-net: | ||
| - | </ | ||
| - | |||
| - | Now, as usual, pull the images: | ||
| - | <code bash> | ||
| - | podman compose pull | ||
| - | </ | ||
| - | |||
| - | Generate initial configuration file: | ||
| - | <code bash> | ||
| - | podman compose run --rm -e SYNAPSE_SERVER_NAME=chat.mydomain.com -e SYNAPSE_REPORT_STATS=yes synapse generate | ||
| - | </ | ||
| - | |||
| - | Edit your **/ | ||
| - | <file - homeserver.yaml> | ||
| - | server_name: | ||
| - | pid_file: / | ||
| - | # NOTE: enable the following two lines ONLY to create users, then REMOVE them! | ||
| - | # | ||
| - | # | ||
| - | listeners: | ||
| - | - port: 8008 | ||
| - | tls: false | ||
| - | type: http | ||
| - | x_forwarded: | ||
| - | resources: | ||
| - | - names: [client, federation] | ||
| - | compress: false | ||
| - | database: | ||
| - | name: psycopg2 | ||
| - | args: | ||
| - | user: synapse | ||
| - | password: <<< | ||
| - | dbname: synapse | ||
| - | host: db | ||
| - | cp_min: 5 | ||
| - | cp_max: 10 | ||
| - | log_config: "/ | ||
| - | media_store_path: | ||
| - | registration_shared_secret: | ||
| - | report_stats: | ||
| - | macaroon_secret_key: | ||
| - | form_secret: | ||
| - | signing_key_path: | ||
| - | trusted_key_servers: | ||
| - | - server_name: | ||
| - | </ | ||
| - | |||
| - | At this point, you are ready to run the Matrix. | ||
| - | |||
| - | ==== Set up Telegram Bridge ==== | ||
| - | |||
| - | The main **docker-compose.yml** above already contains the bridge image, so just run it once to have it create all the files under ***/ | ||
| - | ... | ||
| - | |||
| - | Edit the file **/ | ||
| - | |||
| - | Go to [[https:// | ||
| - | |||
| - | Some hints on **config.yaml**: | ||
| - | * homeserver - address: the URL of your instance (https:// | ||
| - | * homeserver - domain: the URL of your instance, cleaned (chat.mydomain.com, | ||
| - | * appservice - address: the **container name** of the bridge (so, http:// | ||
| - | * appservice - database: i had to switch to SQLite, as i couldn' | ||
| - | * permissions: | ||
| - | * telegram - api_id the API_ID generated on telegram | ||
| - | * telegram - api_hash: API_HASH generated on telegram | ||
| - | * telegram - bot_token: the bot token created on telegram (optional) | ||
| - | |||
| - | Copy the **/ | ||
| - | |||
| - | It is **very** important to note that the // | ||
| - | |||
| - | ===== Reverse Proxy ===== | ||
| - | |||
| - | You need to run your Matrix behind a reverse proxy so that you can easily add SSL and protect your server. See [[selfhost: | ||
| - | |||
| - | This is a simple and effective **chat.conf** for NGINX: | ||
| - | <file - chat.conf> | ||
| - | server { | ||
| - | server_name chat.mydomain.com; | ||
| - | listen 8443 ssl; | ||
| - | listen 443 ssl; | ||
| - | |||
| - | access_log / | ||
| - | error_log / | ||
| - | |||
| - | location ~ ^(/ | ||
| - | # 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:// | ||
| - | 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 500M; | ||
| - | |||
| - | # Synapse responses may be chunked, which is an HTTP/1.1 feature. | ||
| - | proxy_http_version 1.1; | ||
| - | } | ||
| - | include com.mydomain/ | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== Autostart & Running ===== | ||
| - | |||
| - | If you are following my [[gentoo: | ||
| - | <code bash> | ||
| - | cd / | ||
| - | ln -s _servicer.sh 63-synapse--podman.start | ||
| - | ln -s _servicer.sh 63-synapse--podman.stop | ||
| - | </ | ||
| - | |||
| - | ===== User Creation ===== | ||
| - | |||
| - | One of the not so intuitive things about Matrix is user creation. I didnt waste too much time on this because i only needed two users (and in general, only a limited numnber of family members), so i went the manual way. | ||
| - | |||
| - | After starting the containers, as user // | ||
| - | <code bash> | ||
| - | podman compose run --rm --entrypoint /bin/bash synapse | ||
| - | / | ||
| - | </ | ||