💾 Archived View for elmau.net › notes › matrix.gmi captured on 2023-03-20 at 17:39:51. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2023-07-22)

-=-=-=-=-=-=-

Matrix

Matrix es un excelente software de chat descentralizado.

Si bien se puede tener un dominio como nombre de tu servidor, es más practico usar un subdominio, asegurate de tenerlo ya apuntando a tu servidor.

matrix.dominio.net

Instalar dependencias

apt install curl wget gnupg2 apt-transport-https

Agregar la firma de los paquetes

wget -qO /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg

Agregar el repositorio

echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list

Actualizamos el repositorio

apt update

Instalar el servidor

apt install matrix-synapse-py3

Agrega el nombre de tu servidor (matrix.dominio.net) sin ningún protocolo cuando se te solicite.

Instalar Postgres

apt install postgresql

Configura

vim /etc/postgresql/12/main/pg_hba.conf

    local       all     postgres            trust
    local       all     all                 scram-sha-256

Reinicia

systemctl restart postgresql

Entra al shell de postgres

psql -U postgres

Y creas el role y la base de datos:

create role matrix with login encrypted password 'LETMEIN';

create database matrix with owner matrix locale 'C' template template0;

Regresa al shell del server.

Vamos a editar la configuración para que use postgres.

vim /etc/matrix-synapse/homeserver.yaml

Reemplaza en:

database:
  name: psycopg2
  args:
    user: matrix
    password: LETMEIN
    database: matrix
    host: localhost

Al final agregas:

registration_shared_secret: "SUPER-SECRET"

Guardas.

Instalamos el driver para postgres:

apt install python-is-python3 python3-pip

pip install --upgrade pip wheel

pip install psycopg2-binary

Reinicias.

systemctl restart matrix-synapse

Verifica que todo este bien.

systemctl status matrix-synapse

Registra un usuario:

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

Instalamos certbot.

apt install certbot

Nos registramos.

certbot register --agree-tos -m CORREO

Solicitamos el certificado.

certbot certonly --standalone --preferred-challenges http-01 -d matrix.dominio.net

Toma nota de las rutas de los certificados.

Generamos el archivo.

openssl dhparam -dsaparam -out /etc/letsencrypt/ssl-dhparams.pem 4096

Creamos el archivo.

vim /etc/letsencrypt/options-ssl-nginx.conf

con este contenido.

ssl_session_timeout 1440m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";

add_header Strict-Transport-Security "max-age=63072000; preload";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

Creamos el archivo.

vim /etc/letsencrypt/certbot.conf

con este contenido.

ssl_certificate /etc/letsencrypt/live/matrix.dominio.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/matrix.dominio.net/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

Instalamos el servidor web

apt install nginx

Borramos el archivo.

rm /etc/nginx/sites-enabled/default

Editamos el archivo.

vim /etc/nginx/nginx.conf

con el contenido.

user  www-data;
worker_processes  auto;
worker_rlimit_nofile 25600;
pid /run/nginx.pid;

error_log  /var/log/nginx/error.log warn;

events {
    worker_connections  5120;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    server_tokens off;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    keepalive_timeout  65;

    include /etc/nginx/sites-enabled/*.conf;

    disable_symlinks off;

    client_max_body_size 50m;

}

Creamos el archivo

vim /etc/nginx/sites-available/matrix.dominio.net.conf

con el contenido.

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

    # For the federation port
    listen 8448 ssl http2 default_server;
    listen [::]:8448 ssl http2 default_server;

    server_name matrix.dominio.net;
    charset     utf-8;

    include /etc/letsencrypt/certbot.conf;
    server_tokens off;

    access_log      /var/log/nginx/matrix.access.log;
    error_log       /var/log/nginx/matrix.error.log;

    location / {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    location ~* ^(\/_matrix|\/_synapse\/client) {
        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;

        client_max_body_size 10M;
    }
}

Creamos el vínculo simbólico.

ln -s /etc/nginx/sites-available/matrix.dominio.net.conf /etc/nginx/sites-enabled/

Probamos la configuración.

nginx -t

Si todo esta bien, reinicias el servidor web.

systemctl restart nginx

Ya deberías poder acceder desde cualquier cliente Matrix.

¡Disfruta!

Regresar el índice

Regresar el inicio