Initial Commit
This commit is contained in:
318
Guides/Docker/08Matrix.md
Normal file
318
Guides/Docker/08Matrix.md
Normal file
@@ -0,0 +1,318 @@
|
||||
---
|
||||
title: 08 Matrix
|
||||
description:
|
||||
published: true
|
||||
date: 2023-05-03T06:04:33.804Z
|
||||
tags:
|
||||
editor: markdown
|
||||
dateCreated: 2023-05-03T01:58:48.449Z
|
||||
---
|
||||
|
||||
# Matrix
|
||||
WIP!
|
||||
|
||||
# Conduit
|
||||
WIP!
|
||||
|
||||
# Synapse
|
||||
Synapse is a Matrix server, It can be used for all sorts of things, but it is mainly used for private communication. I can certainly recommend it.
|
||||
|
||||
First we need to create a network
|
||||
|
||||
sudo docker network create --subnet=172.32.0.0/16 synapse
|
||||
|
||||
Now create the folder for the project
|
||||
|
||||
mkdir -p ~/docker/synapse
|
||||
|
||||
Now create the compose file
|
||||
|
||||
nano ~/docker/synapse/docker-compose.yml
|
||||
|
||||
Add in the following text
|
||||
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
synapse:
|
||||
image: matrixdotorg/synapse:latest
|
||||
container_name: synapse
|
||||
restart: always
|
||||
volumes:
|
||||
- /data/synapse:/data
|
||||
networks:
|
||||
synapse:
|
||||
ipv4_address: 172.32.0.10
|
||||
|
||||
networks:
|
||||
synapse:
|
||||
external: true
|
||||
name: synapse
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.32.0.0/16
|
||||
|
||||
Now we need to create the database user, database and set the privileges First the user
|
||||
|
||||
sudo docker exec -it -u postgres postgres psql
|
||||
create user synapse with encrypted password 'set your synapse user password here';
|
||||
exit;
|
||||
|
||||
Now the database
|
||||
|
||||
sudo docker exec -it -u postgres postgres bash
|
||||
createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse synapse
|
||||
exit
|
||||
|
||||
And finally the permissions
|
||||
|
||||
sudo docker exec -it -u postgres postgres psql
|
||||
grant all privileges on database synapse to synapse;
|
||||
exit;
|
||||
|
||||
Now we need to run the synapse config generation
|
||||
|
||||
sudo docker run -it --rm -v "/data/synapse:/data" -e SYNAPSE_SERVER_NAME=example.com -e SYNAPSE_REPORT_STATS=yes matrixdotorg/synapse:latest generate
|
||||
|
||||
Now we are going to adjust the config file a bit
|
||||
|
||||
sudo nano /data/synapse/homeserver.yaml
|
||||
|
||||
Here we comment in the sqlite database and uncomment the postgres settings so it looks like this
|
||||
|
||||
database:
|
||||
name: psycopg2
|
||||
txn_limit: 10000
|
||||
args:
|
||||
user: synapse
|
||||
password: the password you set for the synapse user
|
||||
database: synapse
|
||||
host: 172.32.0.30
|
||||
port: 5432
|
||||
cp_min: 5
|
||||
cp_max: 10
|
||||
#database:
|
||||
# name: sqlite3
|
||||
# args:
|
||||
# database: /data/homeserver.db
|
||||
|
||||
We can now start the synapse container
|
||||
|
||||
sudo docker-compose -f ~/docker/synapse/docker-compose.yml up -d
|
||||
|
||||
Now we need to add nginx to the synapse network (notice we already added synapse to postgres)
|
||||
|
||||
nano ~/docker/nginx/docker-compose.yml
|
||||
|
||||
Add the following bits in the correct place
|
||||
|
||||
- 8448:8448
|
||||
|
||||
synapse:
|
||||
ipv4_address: 172.32.0.20
|
||||
|
||||
synapse:
|
||||
external: true
|
||||
name: synapse
|
||||
|
||||
Now we finally add the server block to the nginx config file
|
||||
|
||||
sudo nano /data/nginx/nginx.conf
|
||||
|
||||
Add in the following block
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
|
||||
|
||||
# For the federation port
|
||||
listen 8448 ssl http2 default_server;
|
||||
listen [::]:8448 ssl http2 default_server;
|
||||
|
||||
server_name example.com;
|
||||
|
||||
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://synapse: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;
|
||||
}
|
||||
}
|
||||
|
||||
The last thing we need to do is open up port 8448 in our router.
|
||||
|
||||
Now Synapse should be up and running, as a last step we need to add a user.
|
||||
|
||||
sudo docker exec -it synapse bash
|
||||
register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008
|
||||
|
||||
Simply follow the steps, give a name, give a password, and say wether it is an admin yes or no.
|
||||
|
||||
# Element
|
||||
Element is a Web client for Matrix, You can use it to chat with other Matrix users
|
||||
|
||||
First we are going to create the network
|
||||
|
||||
sudo docker network create --subnet=172.33.0.0/16 element
|
||||
|
||||
Now we are going to create a folder for the compose file
|
||||
|
||||
mkdir ~/docker/element
|
||||
|
||||
Create the compose file
|
||||
|
||||
nano ~/docker/element/docker-compose.yml
|
||||
|
||||
Add in the following text
|
||||
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
element:
|
||||
image: vectorim/element-web:latest
|
||||
container_name: element
|
||||
restart: always
|
||||
volumes:
|
||||
- /data/element/element-config.json:/app/config.json
|
||||
networks:
|
||||
element:
|
||||
ipv4_address: 172.33.0.10
|
||||
|
||||
networks:
|
||||
element:
|
||||
external: true
|
||||
name: element
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.33.0.0/16
|
||||
|
||||
Now we need to create the element folder for the data
|
||||
|
||||
sudo mkdir /data/element/
|
||||
|
||||
Now we are going to create element the config file
|
||||
|
||||
sudo nano /data/element/element-config.json
|
||||
|
||||
Add in the following text
|
||||
|
||||
{
|
||||
"default_server_config": {
|
||||
"m.homeserver": {
|
||||
"base_url": "https://example.com",
|
||||
"server_name": "example.com"
|
||||
},
|
||||
"m.identity_server": {
|
||||
"base_url": "https://vector.im"
|
||||
}
|
||||
},
|
||||
"brand": "Element",
|
||||
"integrations_ui_url": "https://scalar.vector.im/",
|
||||
"integrations_rest_url": "https://scalar.vector.im/api",
|
||||
"integrations_widgets_urls": [
|
||||
"https://scalar.vector.im/_matrix/integrations/v1",
|
||||
"https://scalar.vector.im/api",
|
||||
"https://scalar-staging.vector.im/_matrix/integrations/v1",
|
||||
"https://scalar-staging.vector.im/api",
|
||||
"https://scalar-staging.riot.im/scalar/api"
|
||||
],
|
||||
"hosting_signup_link": "https://element.io/matrix-services?utm_source=element-web&utm_medium=web",
|
||||
"bug_report_endpoint_url": "https://element.io/bugreports/submit",
|
||||
"uisi_autorageshake_app": "element-auto-uisi",
|
||||
"showLabsSettings": true,
|
||||
"piwik": {
|
||||
"url": "https://piwik.riot.im/",
|
||||
"siteId": 1,
|
||||
"policyUrl": "https://element.io/cookie-policy"
|
||||
},
|
||||
"roomDirectory": {
|
||||
"servers": [
|
||||
"matrix.org",
|
||||
"gitter.im",
|
||||
"libera.chat"
|
||||
]
|
||||
},
|
||||
"enable_presence_by_hs_url": {
|
||||
"https://matrix.org": false,
|
||||
"https://matrix-client.matrix.org": false
|
||||
},
|
||||
"terms_and_conditions_links": [
|
||||
{
|
||||
"url": "https://element.io/privacy",
|
||||
"text": "Privacy Policy"
|
||||
},
|
||||
{
|
||||
"url": "https://element.io/cookie-policy",
|
||||
"text": "Cookie Policy"
|
||||
}
|
||||
],
|
||||
"hostSignup": {
|
||||
"brand": "Element Home",
|
||||
"cookiePolicyUrl": "https://element.io/cookie-policy",
|
||||
"domains": [
|
||||
"matrix.org"
|
||||
],
|
||||
"privacyPolicyUrl": "https://element.io/privacy",
|
||||
"termsOfServiceUrl": "https://element.io/terms-of-service",
|
||||
"url": "https://ems.element.io/element-home/in-app-loader"
|
||||
},
|
||||
"sentry": {
|
||||
"dsn": "https://029a0eb289f942508ae0fb17935bd8c5@sentry.matrix.org/6",
|
||||
"environment": "develop"
|
||||
},
|
||||
"posthog": {
|
||||
"projectApiKey": "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO",
|
||||
"apiHost": "https://posthog.hss.element.io"
|
||||
},
|
||||
"features": {
|
||||
"feature_spotlight": true
|
||||
},
|
||||
"map_style_url": "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx"
|
||||
}
|
||||
|
||||
Now we are going to add the network to the nginx compose file
|
||||
|
||||
nano ~/docker/nginx/docker-compose.yml
|
||||
|
||||
Add the following to the correct place
|
||||
|
||||
element:
|
||||
ipv4_address: 172.33.0.20
|
||||
|
||||
element:
|
||||
external: true
|
||||
name: element
|
||||
|
||||
Now we only need to edit the nginx config file
|
||||
|
||||
sudo nano /data/nginx/nginx.conf
|
||||
|
||||
Add in the following location block between the synapse server
|
||||
|
||||
location / {
|
||||
proxy_pass http://element:80;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Host $remote_addr;
|
||||
}
|
||||
|
||||
Now finally restart the nginx container and start the element container.
|
||||
|
||||
sudo docker-compose -f ~/docker/nginx/docker-compose.yml up -d
|
||||
sudo docker-compose -f ~/docker/element/docker-compose.yml up -d
|
||||
|
||||
Element should be ready to use :)
|
||||
|
||||
# Synapse Admin
|
||||
WIP!
|
||||
Reference in New Issue
Block a user