Cách cài đặt và tạo máy chủ trò chuyện bằng Matrix Synapse và Element trên Rocky Linux 9

theanh

Administrator
Nhân viên
Matrix là một tiêu chuẩn mở cho giao tiếp phi tập trung và được mã hóa đầu cuối. Đây là một tập hợp các máy chủ và dịch vụ giao tiếp với nhau bằng API chuẩn hóa đồng bộ hóa theo thời gian thực. Nó sử dụng máy chủ gia đình để lưu trữ thông tin tài khoản và lịch sử trò chuyện. Nếu một máy chủ gia đình ngừng hoạt động, các máy chủ khác có thể tiếp tục giao tiếp mà không có vấn đề gì do bản chất của sự phi tập trung. Bạn có thể sử dụng máy chủ gia đình Matrix do người khác lưu trữ hoặc máy chủ của riêng bạn để duy trì quyền kiểm soát dữ liệu của mình.

Trong hướng dẫn này, bạn sẽ tìm hiểu cách cài đặt và tạo máy chủ trò chuyện bằng Synapse, một triển khai máy chủ gia đình của Matrix. Element là một máy khách web Matrix được xây dựng bằng Matrix React SDK. Điều này sẽ cho phép bạn cung cấp trò chuyện Matrix trên web. Bạn cũng có thể sử dụng máy chủ với bất kỳ máy khách Matrix nào khác. Chúng tôi cũng sẽ cài đặt máy chủ Coturn để kích hoạt tính năng gọi thoại và gọi video. Dịch vụ Coturn là tùy chọn nếu bạn không muốn sử dụng dịch vụ này.

Điều kiện tiên quyết​


  1. Máy chủ chạy Debian 12.

  2. Người dùng không sử dụng sudo có quyền root.

  3. Tường lửa đơn giản (UFW) được bật và đang chạy.

  4. Tên miền đủ điều kiện (FQDN) cho Matrix, Element và Coturn trỏ đến máy chủ của bạn. Chúng tôi sẽ sử dụng matrix.example.com, element.example.comcoturn.example.com tương ứng cho ba dịch vụ.

  5. Đảm bảo rằng mọi thứ đều được cập nhật.
    Mã:
    $ sudo dnf update

  • Một số gói mà hệ thống của bạn nhu cầu.
    Mã:
    $ sudo dnf install wget curl nano unzip yum-utils policycoreutils-python-utils -y
    Một số gói này có thể đã được cài đặt trên hệ thống của bạn.

Bước 1 - Cấu hình Tường lửa​

Trước khi cài đặt bất kỳ gói nào, bước đầu tiên là cấu hình tường lửa để mở cổng cho HTTP, HTTPS và Synapse. Rocky Linux sử dụng Tường lửa Firewalld. Kiểm tra trạng thái của tường lửa.
Mã:
$ sudo firewall-cmd --state
running
Tường lửa hoạt động với nhiều vùng khác nhau và vùng công cộng là vùng mặc định mà chúng ta sẽ sử dụng. Liệt kê tất cả các dịch vụ và cổng đang hoạt động trên tường lửa.
Mã:
$ sudo firewall-cmd --zone=public --list-all
Nó sẽ hiển thị đầu ra sau.
Mã:
public target: default icmp-block-inversion: no interfaces: enp1s0 sources: services: cockpit dhcpv6-client ssh ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
Mở các cổng HTTP, HTTPS và Synapse trong tường lửa.
Mã:
$ sudo firewall-cmd --zone=public --add-port=8448/tcp
$ sudo firewall-cmd --zone=public --add-service=http
$ sudo firewall-cmd --zone=public --add-service=https
Kiểm tra lại trạng thái của tường lửa.
Mã:
$ sudo firewall-cmd --zone=public --list-all
Bạn sẽ thấy một đầu ra.
Mã:
public target: default icmp-block-inversion: no interfaces: enp1s0 sources: services: cockpit dhcpv6-client http https ssh ports: 8448/tcp protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
Thực hiện tất cả các thay đổi vĩnh viễn và tải lại tường lửa để kích hoạt các thay đổi.
Mã:
$ sudo firewall-cmd --runtime-to-permanent
$ sudo firewall-cmd --reload

Bước 2 - Cài đặt và cấu hình PostgreSQL​

Rocky Linux 9 được tích hợp sẵn PostgreSQL 13 theo mặc định. Chúng tôi sẽ sử dụng PostgreSQL 16 từ kho lưu trữ chính thức của nó.

Cài đặt kho lưu trữ PostgreSQL RPM.
Mã:
$ sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Vô hiệu hóa mô-đun PostgreSQL tích hợp sẵn.
Mã:
$ sudo dnf -qy module disable postgresql
Bây giờ, bạn có thể cài đặt PostgreSQL bằng cách sử dụng lệnh sau lệnh.
Mã:
$ sudo dnf install -y postgresql16-server postgresql16-contrib postgresql16-devel
sudo dnf install postgresql16-devel

export PATH=$PATH:/usr/pgsql-16/bin

Gói postgresql-contrib chứa một số tiện ích bổ sung.

Xác minh phiên bản.
Mã:
$ psql --version
psql (PostgreSQL) 16.1
Khởi tạo cơ sở dữ liệu PostgreSQL.
Mã:
$ sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
Initializing database ... OK
Kích hoạt PostgreSQL dịch vụ.
Mã:
$ sudo systemctl enable postgresql-16
Khởi động dịch vụ PostgreSQL.
Mã:
$ sudo systemctl start postgresql-16
Kiểm tra trạng thái của dịch vụ PostgreSQL.
Mã:
$ sudo systemctl status postgresql-16
? postgresql-16.service - PostgreSQL 16 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-16.service; enabled; preset: disabled) Active: active (running) since Tue 2024-01-30 11:55:26 UTC; 10s ago Docs: https://www.postgresql.org/docs/16/static/ Process: 9610 ExecStartPre=/usr/pgsql-16/bin/postgresql-16-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 9615 (postgres) Tasks: 7 (limit: 12225) Memory: 17.4M CPU: 98ms CGroup: /system.slice/postgresql-16.service ??9615 /usr/pgsql-16/bin/postgres -D /var/lib/pgsql/16/data/ ??9616 "postgres: logger " ??9617 "postgres: checkpointer " ??9618 "postgres: background writer " ??9620 "postgres: walwriter " ??9621 "postgres: autovacuum launcher " ??9622 "postgres: logical replication launcher "
Jan 30 11:55:26 matrix.example.com systemd[1]: Starting PostgreSQL 16 database server...
Jan 30 11:55:26 matrix.example.com postgres[9615]: 2024-01-30 11:55:26.482 UTC [9615] LOG: redirecting log output to logging collector process
Jan 30 11:55:26 matrix.example.com postgres[9615]: 2024-01-30 11:55:26.482 UTC [9615] HINT: Future log output will appear in directory "log".
Jan 30 11:55:26 matrix.example.com systemd[1]: Started PostgreSQL 16 database server.
Bạn có thể thấy rằng dịch vụ được bật và chạy theo mặc định.

Đăng nhập vào postgres tài khoản hệ thống.
Mã:
$ sudo -su postgres
Tạo người dùng cơ sở dữ liệu mới và cơ sở dữ liệu cho PostgreSQL. Bạn sẽ được nhắc nhập mật khẩu khi tạo người dùng.
Mã:
$ createuser --pwprompt synapse
$ createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse synapsedb
Thoát khỏi postgres account.
Mã:
$ exit

Bước 3 - Cài đặt Matrix Synapse​

Matrix Synapse không có gói dựng sẵn cho các bản phân phối dựa trên CentOS như Rocky Linux. Do đó, chúng tôi sẽ cài đặt nó dưới dạng mô-đun Python từ PyPI.

Bước đầu tiên là cài đặt các điều kiện tiên quyết cần thiết để Synapse hoạt động. Chúng tôi cũng cần kho lưu trữ EPEL bao gồm gói python3-virtualenv.
Mã:
$ sudo dnf install epel-release
$ sudo dnf install --enablerepo=crb libtiff-devel libjpeg-devel libzip-devel \ freetype-devel libwebp-devel libxml2-devel libxslt-devel \ libpq-devel python3-virtualenv libffi-devel openssl-devel \ python3-devel libicu-devel
$ sudo dnf groupinstall "Development Tools"
$ sudo dnf install postgresql16-devel
Tạo thư mục cho Synapse.
Mã:
$ mkdir -p ~/synapse
Tạo môi trường ảo Python trong thư mục đã nói.
Mã:
$ virtualenv -p python3 ~/synapse/env
Kích hoạt môi trường ảo môi trường.
Mã:
$ source ~/synapse/env/bin/activate
Đảm bảo rằng bạn có phiên bản mới nhất của pipsetuptools.
Mã:
(env) $ pip install --upgrade pip
(env) $ pip install --upgrade setuptools
Cài đặt Matrix Synapse.
Mã:
(env) $ pip install "matrix-synapse[postgres]"
Điều này sẽ tải xuống Synapse từ PyPI và cài đặt nó, cùng với các thư viện Python mà nó sử dụng vào một môi trường ảo trong thư mục ~/synapse/env. Nó cũng sẽ cài đặt thư viện Python PostgreSQL cần thiết để Synapse kết nối với máy chủ PostgreSQL. Lệnh trên là sự kết hợp của các lệnh pip install matrix-synapsepip install psycopg2.

Bước tiếp theo là tạo tệp cấu hình với một số cài đặt cơ bản. Chuyển sang thư mục Synapse.
Mã:
(env) $ cd ~/synapse
Chạy lệnh sau để tạo tệp cấu hình.
Mã:
(env) $ python -m synapse.app.homeserver \ --server-name matrix.example.com \ --config-path homeserver.yaml \ --generate-config \ --report-stats=[yes|no]
Giá trị của Biến --server-name tạo thành một phần của ID Matrix của bạn. Nhập tên miền Matrix của bạn làm giá trị của nó. Điều này sẽ hoạt động như địa chỉ máy chủ gia đình của bạn.

Bạn có thể chọn có muốn gửi số liệu thống kê ẩn danh về máy chủ gia đình của bạn trở lại Matrix thông qua biến --report-stats hay không. Chọn yes hoặc no theo lựa chọn của bạn.

Bạn sẽ nhận được kết quả sau.
Mã:
Generating config file homeserver.yaml
Generating log config file /home/navjot/synapse/matrix.example.com.log.config which will log to /home/navjot/synapse/homeserver.log
Generating signing key file /home/navjot/synapse/matrix.example.com.signing.key
A config file has been generated in 'homeserver.yaml' for server name 'matrix.example.com'. Please review this file and customise it to your needs.
Bạn có thể thay đổi các thiết lập này sau trong tệp ~/synapse/homeserver.yaml hoặc /home//synapse/homeserver.yaml tệp. Các khóa được tạo bởi lệnh trên sẽ cho phép máy chủ gia đình của bạn tự nhận dạng với máy chủ gia đình khác.

Đã đến lúc chạy máy chủ Matrix. Đảm bảo bạn đang ở trong thư mục Synapse và môi trường ảo đang hoạt động.

Khởi động máy chủ tại nhà.
Mã:
(env) $ synctl start
Bạn sẽ thấy đầu ra tương tự.
Mã:
This server is configured to use 'matrix.org' as its trusted key server via the
'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
server since it is long-lived, stable and trusted. However, some admins may
wish to use another server for this purpose.
To suppress this warning and continue using 'matrix.org', admins should set
'suppress_key_server_warning' to 'true' in homeserver.yaml.
--------------------------------------------------------------------------------
started synapse.app.homeserver(homeserver.yaml)
Để dừng máy chủ, hãy chạy lệnh sau lệnh.
Mã:
(env) $ synctl stop
Hủy kích hoạt môi trường ảo.
Mã:
(env) $ deactivate

Bước 4 - Cài đặt Nginx​

Đối với môi trường sản xuất, bạn nên chạy máy chủ Synapse bằng proxy Nginx.

Rocky Linux 9 đi kèm với phiên bản cũ hơn của Nginx. Bạn cần sử dụng kho lưu trữ Nginx chính thức để cài đặt phiên bản mới nhất.

Tạo và mở tệp /etc/yum.repos.d/nginx.repo để chỉnh sửa.
Mã:
$ sudo nano /etc/yum.repos.d/nginx.repo
Dán mã sau vào nó.
Mã:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
Sau khi hoàn tất, hãy lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Chúng tôi sẽ cài đặt dòng chính Nginx nên hãy bật gói cho nó.
Mã:
$ sudo dnf config-manager --enable nginx-mainline
Cài đặt Nginx.
Mã:
$ sudo dnf install nginx -y
Xác minh cài đặt.
Mã:
$ nginx -v
nginx version: nginx/1.25.3
Bật và khởi động máy chủ Nginx dịch vụ.
Mã:
$ sudo systemctl enable nginx --now
Kiểm tra trạng thái của dịch vụ.
Mã:
$ sudo systemctl status nginx
? nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled) Active: active (running) since Tue 2024-01-30 12:50:34 UTC; 4s ago Docs: http://nginx.org/en/docs/ Process: 10810 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 10811 (nginx) Tasks: 3 (limit: 12225) Memory: 3.1M CPU: 24ms CGroup: /system.slice/nginx.service ??10811 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf" ??10812 "nginx: worker process" ??10813 "nginx: worker process"

Bước 5 - Cài đặt SSL​

Chúng ta cần cài đặt Certbot để tạo chứng chỉ SSL. Chúng ta sẽ sử dụng trình cài đặt gói Snapd cho việc đó. Vì Rocky Linux không đi kèm với nó, hãy cài đặt trình cài đặt Snapd. Nó yêu cầu kho lưu trữ EPEL (Gói bổ sung cho Enterprise Linux) để hoạt động. Nhưng vì chúng ta đã cài đặt nó ở bước 3, nên chúng ta có thể trực tiếp tiến hành.

Cài đặt gói Snapd.
Mã:
$ sudo dnf install snapd -y
Bật và khởi động dịch vụ Snap.
Mã:
$ sudo systemctl enable snapd --now
Cài đặt gói lõi Snap và đảm bảo rằng phiên bản Snapd của bạn là ngày.
Mã:
$ sudo snap install core
$ sudo snap refresh core
Tạo các liên kết cần thiết để Snapd hoạt động.
Mã:
$ sudo ln -s /var/lib/snapd/snap /snap
$ echo 'export PATH=$PATH:/var/lib/snapd/snap/bin' | sudo tee -a /etc/profile.d/snapd.sh
Cài đặt Certbot.
Mã:
$ sudo snap install --classic certbot
Sử dụng lệnh sau để đảm bảo lệnh Certbot có thể chạy bằng cách tạo liên kết tượng trưng đến thư mục /usr/bin.
Mã:
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
Kiểm tra Certbot phiên bản.
Mã:
$ certbot --version
certbot 2.8.0
Chạy lệnh sau để tạo Chứng chỉ SSL.
Mã:
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [emailprotected] -d matrix.example.com
Lệnh trên sẽ tải xuống chứng chỉ vào /etc/letsencrypt/live/matrix.example.com thư mục trên máy chủ của bạn.

Tạo chứng chỉ nhóm Diffie-Hellman.
Mã:
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
Kiểm tra trình lập lịch gia hạn Certbot dịch vụ.
Mã:
$ systemctl list-timers
Bạn sẽ thấy snap.certbot.renew.service là một trong những dịch vụ được lên lịch chạy.
Mã:
NEXT LEFT LAST PASSED UNIT ACTIVATES ----------------------------------------------------------------------------------------------------------------------------------
Tue 2024-01-30 14:37:50 UTC 29min left Tue 2024-01-30 13:05:13 UTC 1h 3min ago dnf-makecache.timer dnf-makecache.service
Tue 2024-01-30 15:13:00 UTC 1h 4min left - - snap.certbot.renew.timer snap.certbot.renew.service
Wed 2024-01-31 00:00:00 UTC 9h left Tue 2024-01-30 06:35:44 UTC 7h ago logrotate.timer logrotate.service
Thực hiện chạy thử quy trình để kiểm tra xem quá trình gia hạn SSL có hoạt động tốt không.
Mã:
$ sudo certbot renew --dry-run
Nếu không thấy lỗi nào, bạn đã hoàn tất. Chứng chỉ của bạn sẽ tự động gia hạn.

Bước 6 - Cấu hình SELinux​

SELinux ngăn bạn chạy dịch vụ hệ thống có tệp nhị phân nằm trong thư mục gốc của người dùng. Vì lý do này, nếu chúng ta tạo tệp dịch vụ cho Synapse, tệp đó sẽ bị SELinux chặn. Để giải quyết vấn đề này, chúng ta cần chạy lệnh sau để cho phép chạy tệp nhị phân Python dưới dạng dịch vụ hệ thống.
Mã:
$ sudo chcon -R -t bin_t /home/username/synapse/env/bin/python
Áp dụng chính sách để cho phép kết nối được thực hiện với các máy chủ bên ngoài.
Mã:
$ sudo setsebool -P httpd_can_network_connect 1
Áp dụng chính sách để cho phép Nginx cấp quyền truy cập vào PostgreSQL.
Mã:
$ sudo setsebool -P httpd_can_network_connect_db 1

Bước 7 - Tạo dịch vụ Matrix Systemd​

Trạng thái dịch vụ Synapse không được lưu khi khởi động lại, điều này có nghĩa là nếu bạn khởi động lại máy chủ, bạn sẽ cần phải khởi động máy chủ theo cách thủ công. Để giải quyết vấn đề này, chúng ta cần tạo tệp Systemd cho nó.

Trước khi tiến hành, hãy đảm bảo dịch vụ Synapse đã dừng.
Mã:
$ cd ~/synapse
$ source env/bin/activate
(env) $ synctl stop
(env) $ deactivate
Tạo và mở tệp matrix-synapse.service trong /etc/systemd/system/ thư mục để chỉnh sửa.
Mã:
$ sudo nano /etc/systemd/system/matrix-synapse.service
Dán mã sau vào đó. Thay thế biến username bằng người dùng hệ thống Linux mà bạn đã cài đặt Synapse.
Mã:
# This assumes that Synapse has been installed by a user named username.
# This assumes that Synapse has been installed in a virtualenv in
# the user's home directory: `/home/username/synapse/env`.
[Unit]
Description=Synapse Matrix homeserver
After=postgresql-16.service
[Service]
Type=notify
NotifyAccess=main
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-abort
WorkingDirectory=/home/username/synapse
ExecStart=/home/username/synapse/env/bin/python -m synapse.app.homeserver --config-path=/home/username/synapse/homeserver.yaml
SyslogIdentifier=matrix-synapse
# adjust the cache factor if necessary
# Environment=SYNAPSE_CACHE_FACTOR=2.0
[Install]
WantedBy=multi-user.target
Sau khi hoàn tất, hãy lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Tải lại dịch vụ daemon.
Mã:
$ sudo systemctl daemon-reload
Kích hoạt dịch vụ Matrix Synapse.
Mã:
$ sudo systemctl enable matrix-synapse
Khởi động Matrix Synapse dịch vụ.
Mã:
$ sudo systemctl start matrix-synapse
Kiểm tra trạng thái dịch vụ.
Mã:
$ sudo systemctl status matrix-synapse
Bạn sẽ thấy kết quả sau.
Mã:
? matrix-synapse.service - Synapse Matrix homeserver Loaded: loaded (/etc/systemd/system/matrix-synapse.service; enabled; preset: disabled) Active: active (running) since Tue 2024-01-30 14:20:20 UTC; 5s ago Main PID: 14687 (python) Tasks: 8 (limit: 12225) Memory: 77.6M CPU: 3.527s CGroup: /system.slice/matrix-synapse.service ??14687 /home/navjot/synapse/env/bin/python -m synapse.app.homeserver --config-path=/home/navjot/synapse/homeserver.yaml
Jan 30 14:20:16 matrix.example.com systemd[1]: Starting Synapse Matrix homeserver...
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: This server is configured to use 'matrix.org' as its trusted key server via the
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: 'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: server since it is long-lived, stable and trusted. However, some admins may
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: wish to use another server for this purpose.
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: To suppress this warning and continue using 'matrix.org', admins should set
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: 'suppress_key_server_warning' to 'true' in homeserver.yaml.
Jan 30 14:20:19 matrix.example.com matrix-synapse[14687]: --------------------------------------------------------------------------------
Jan 30 14:20:20 matrix.example.com systemd[1]: Started Synapse Matrix homeserver.

Bước 8 - Cấu hình Matrix Synapse​

Trước khi tiếp tục, hãy tạo khóa đăng ký bí mật trước. Khóa phải được bảo mật vì nó sẽ cho phép bất kỳ ai đăng ký người dùng mới, ngay cả khi đăng ký bị vô hiệu hóa.
Mã:
$ echo "registration_shared_secret: '$(cat /dev/urandom | tr -cd '[:alnum:]' | fold -w 256 | head -n 1)'"
registration_shared_secret: '1y75ja0RUxvbWcS6SdZhakenukUwHHEjOXWC9Mu3FpO0QenOnpKRsc6NBZSxuzPcHYsOEuIQziwVjSZcP87dlWK4ZkIGYniurMqNsCYL4xg5xXs4bJDuTJH2CUXab4U9liv399lmkIZFaMpJCLxV9lVWB9mKHILYsjeLgGY5wAARv1SiK07bFsQOwKJGFqIvsUXmxymx5QCNDzTHw8R4ShqZ7elnnZrbdYk4r2f7qogERNHvQaRV7IEYUIOtMhVP'
Sao chép đầu ra từ dòng trên và lưu lại.

Bạn có thể cấu hình máy chủ Matrix thông qua tệp /home/username/synapse/homeserver.yaml. Mở tệp để chỉnh sửa.
Mã:
$ nano ~/synapse/homeserver.yaml
Dán đầu ra của lệnh khóa đăng ký vào cuối tệp.

Theo mặc định, Synapse được cấu hình để sử dụng cơ sở dữ liệu SQLite. Chúng ta cần chỉnh sửa nó để thêm thông tin xác thực PostgreSQL.

Tìm phần sau trong tệp và bình luận như hình minh họa.
Mã:
#database:
# name: sqlite3
# args:
# database: /home/navjot/synapse/homeserver.db
Thêm phần sau bên dưới. Thay thế trường your-password bằng mật khẩu người dùng PostgreSQL mà bạn đã tạo ở bước 3. Thay thế localhost bằng địa chỉ IP của máy chủ của bạn, nếu bạn đang lưu trữ cơ sở dữ liệu ở nơi khác.
Mã:
database: name: psycopg2 args: user: synapse password: 'your-password' database: synapsedb host: localhost cp_min: 5 cp_max: 10
Theo mặc định, Synapse bật các chỉ báo hiện diện cho biết một người có trực tuyến hay không. Nó có thể gây ra tình trạng sử dụng CPU cao, do đó bạn có thể tắt nó. Dán dòng sau vào cuối.
Mã:
presence: enabled: false
Sau khi hoàn tất, hãy lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Tạo người dùng ma trận mới. Bạn sẽ được yêu cầu nhập tên người dùng và mật khẩu. Vì đây là người dùng đầu tiên chúng ta tạo, hãy nhập yes khi được hỏi có muốn biến người dùng thành quản trị viên hay không. Bạn sẽ cần kích hoạt môi trường ảo để tạo người dùng.
Mã:
$ cd ~/synapse
$ source env/bin/activate
(env) $ register_new_matrix_user -c homeserver.yaml http://localhost:8008
New user localpart [navjot]: navjot
Password:
Confirm password:
Make admin [no]: yes
Sending registration request...
Success!
(env) $ deactivate
Bạn có thể thấy rằng chúng ta đã sử dụng cổng 8008 trong lệnh trên. Bởi vì đây là cổng mặc định mà Matrix Synapse lắng nghe.

Theo mặc định, việc đăng ký người dùng mới bị vô hiệu hóa, nghĩa là bạn cần phải đăng ký thủ công từng người dùng như trên. Nếu bạn muốn mở đăng ký công khai, bạn có thể thực hiện bằng cách chỉnh sửa tệp homeserver.yaml.

Mở lại để chỉnh sửa.
Mã:
$ nano ~/synapse/homeserver.yaml
Dán dòng sau vào bottom.
Mã:
enable_registration: true
Theo mặc định, Synapse không cho phép đăng ký mà không xác minh email. Để bật xác minh email, hãy dán các dòng sau.
Mã:
registrations_require_3pid: - email
email: smtp_host: mail.example.com smtp_port: 587 # If mail server has no authentication, skip these 2 lines smtp_user: '[emailprotected]' smtp_pass: 'password' # Optional, require encryption with STARTTLS require_transport_security: true app_name: 'HowtoForge Example Chat' # defines value for %(app)s in notif_from and email subject notif_from: "%(app)s "
Để vô hiệu hóa xác minh email, hãy dán dòng sau vào thay thế.
Mã:
enable_registration_without_verification: true
Sau khi hoàn tất, hãy lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Khởi động lại Synapse để áp dụng cấu hình.
Mã:
$ sudo systemctl restart matrix-synapse

Bước 9 - Cấu hình Nginx​

Mở tệp /etc/nginx/nginx.conf để chỉnh sửa.
Mã:
$ sudo nano /etc/nginx/nginx.conf
Thêm dòng sau vào trước dòng include /etc/nginx/conf.d/*.conf;.
Mã:
server_names_hash_bucket_size 64;
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Tạo và mở tệp /etc/nginx/conf.d/synapse.conf để chỉnh sửa.
Mã:
$ sudo nano /etc/nginx/conf.d/synapse.conf
Dán mã sau vào nó.
Mã:
# enforce HTTPS
server { # Client port listen 80; listen [::]:80; server_name matrix.example.com; return 301 https://$host$request_uri;
}
server { server_name matrix.example.com; # Client port listen 443 ssl; listen [::]:443 ssl; http2 on; # Federation port listen 8448 ssl default_server; listen [::]:8448 ssl default_server; access_log /var/log/nginx/synapse.access.log; error_log /var/log/nginx/synapse.error.log; # TLS configuration ssl_certificate /etc/letsencrypt/live/matrix.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/matrix.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/matrix.example.com/chain.pem; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_prefer_server_ciphers on; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] 8.8.8.8 8.8.4.4 [2001:4860:4860::8888] [2001:4860:4860::8844] valid=60s; resolver_timeout 2s; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; tcp_nopush on; gzip on; location ~ ^(/_matrix|/_synapse/client) { proxy_pass http://localhost:8008; proxy_http_version 1.1; 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; }
}
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc sau khi hoàn tất. Cấu hình trên hoạt động dựa trên giả định rằng địa chỉ IP của miền example.commatrix.example.com đang trỏ đến cùng một máy chủ. Nếu không, hãy sử dụng tệp cấu hình sau cho máy chủ example.com.
Mã:
server { server_name example.com; listen 443 ssl http2; listen [::]:443 ssl http2; # TLS configuration ssl_certificate /etc/letsencrypt/live/matrix.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/matrix.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/matrix.example.com/chain.pem; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_prefer_server_ciphers on; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] 8.8.8.8 8.8.4.4 [2001:4860:4860::8888] [2001:4860:4860::8844] valid=60s; resolver_timeout 2s; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; # Redirect location ~ ^(/_matrix|/_synapse/client) { return 301 "https://matrix.example.com$request_uri"; } # Client homeserver autodiscovery location /.well-known/matrix/client { default_type application/json; add_header Access-Control-Allow-Origin *; return 200 '{ "m.homeserver": { "base_url": "https://matrix.example.com" } }'; } # Domain delegation location /.well-known/matrix/server { default_type application/json; add_header Access-Control-Allow-Origin *; return 200 '{ "m.server": "matrix.example.com" }'; }
}
Xác minh cú pháp tệp cấu hình Nginx.
Mã:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Khởi động lại Nginx dịch vụ.
Mã:
$ sudo systemctl restart nginx

Bước 10 - Cài đặt Coturn​

Bạn sẽ cần cài đặt Traversal Using Relays xung quanh máy chủ NAT (TURN) để kích hoạt cuộc gọi thoại và video. Với mục đích này, chúng tôi sẽ cài đặt gói Coturn. Nếu bạn không cần chức năng này, bạn có thể bỏ qua bước này.

Cài đặt Coturn.
Mã:
$ sudo dnf install coturn
Mở các cổng TURN và UDP.
Mã:
$ sudo firewall-cmd --zone=public --add-port=3478/{tcp,udp}
$ sudo firewall-cmd --zone=public --add-port=5349/{tcp,udp}
$ sudo firewall-cmd --zone=public --add-port=49152-65535/udp
$ sudo firewall-cmd --runtime-to-permanent
$ sudo firewall-cmd --reload
Tạo chứng chỉ SSL cho Turn (coturn.example.com).
Mã:
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [emailprotected] -d coturn.example.com
Tạo bí mật xác thực cho Coturn.
Mã:
$ echo "static-auth-secret=$(cat /dev/urandom | tr -cd '[:alnum:]' | fold -w 256 | head -n 1)"
static-auth-secret=u3ksgJ9X876sFMO00A8KabXwZvzVwCmV30wWvZ7DzGiepRwNRYSCTYzf2E8olNzdDHu7oO3XpT3l5bv5mVdhXEQ3pnoTWBquSVPFFBJtyD6y9gBxiMaD2TYTD2WohQLE9s7OKJVpkDeKTnZQnkmjrFadE3M9DRxPL1W5Lgdg6XLLKABgb5XGkutRgkJOV0JRH4sBYsot63fWq9mcGTm6nAMdIycvDVDOs7vhoeqRzcTbMF0wsfAHVJNhXpGGFDyZ
Mở tệp cấu hình để chỉnh sửa.
Mã:
$ sudo nano /etc/coturn/turnserver.conf
Chúng ta sẽ xem qua tệp và kích hoạt các cài đặt cần thiết. Đầu tiên, hãy bật phương thức xác thực bằng cách bỏ chú thích ở dòng use-auth-secret.
Mã:
# Be aware that use-auth-secret overrides some parts of lt-cred-mech.
# The use-auth-secret feature depends internally on lt-cred-mech, so if you set
# this option then it automatically enables lt-cred-mech internally
# as if you had enabled both.
#
# Note that you can use only one auth mechanism at the same time! This is because,
# both mechanisms conduct username and password validation in different ways.
#
# Use either lt-cred-mech or use-auth-secret in the conf
# to avoid any confusion.
#
use-auth-secret
Tiếp theo, chúng ta sẽ cấu hình static-auth-secret biến với giá trị chúng ta đã tạo ở trên. Chúng ta cũng sẽ cần bí mật này để cấu hình Synapse sau này.
Mã:
# 'Static' authentication secret value (a string) for TURN REST API only.
# If not set, then the turn server
# will try to use the 'dynamic' value in the turn_secret table
# in the user database (if present). The database-stored value can be changed on-the-fly
# by a separate program, so this is why that mode is considered 'dynamic'.
#
static-auth-secret=u3ksgJ9X876sFMO00A8KabXwZvzVwCmV30wWvZ7DzGiepRwNRYSCTYzf2E8olNzdDHu7oO3XpT3l5bv5mVdhXEQ3pnoTWBquSVPFFBJtyD6y9gBxiMaD2TYTD2WohQLE9s7OKJVpkDeKTnZQnkmjrFadE3M9DRxPL1W5Lgdg6XLLKABgb5XGkutRgkJOV0JRH4sBYsot63fWq9mcGTm6nAMdIycvDVDOs7vhoeqRzcTbMF0wsfAHVJNhXpGGFDyZ
Giá trị tiếp theo chúng ta cần thay đổi là realm. Giá trị này đề cập đến miền chúng ta đã chọn cho Coturn.
Mã:
# The default realm to be used for the users when no explicit
# origin/realm relationship is found in the database, or if the TURN
# server is not using any database (just the commands-line settings
# and the userdb file). Must be used with long-term credentials
# mechanism or with TURN REST API.
#
# Note: If the default realm is not specified, then realm falls back to the host domain name.
# If the domain name string is empty, or set to '(None)', then it is initialized as an empty string.
#
realm=coturn.example.com
Tiếp theo, hãy xác định số phiên và số phiên cho mỗi người dùng. Chọn giá trị phù hợp với máy chủ của bạn.
Mã:
# Per-user allocation quota.
# default value is 0 (no quota, unlimited number of sessions per user).
# This option can also be set through the database, for a particular realm.
#
user-quota=12
# Total allocation quota.
# default value is 0 (no quota).
# This option can also be set through the database, for a particular realm.
#
total-quota=1200
Tiếp theo, chúng ta cần tắt TCP vì VOIP là UDP.
Mã:
# Uncomment if no TCP relay endpoints are allowed.
# By default TCP relay endpoints are enabled (like in RFC 6062).
#
no-tcp-relay
Chúng ta cũng cần cấu hình vị trí của các chứng chỉ đã tạo cho Coturn.
Mã:
# Certificate file.
# Use an absolute path or path relative to the
# configuration file.
# Use PEM file format.
#
cert=/etc/letsencrypt/live/coturn.example.com/fullchain.pem
# Private key file.
# Use an absolute path or path relative to the
# configuration file.
# Use PEM file format.
#
pkey=/etc/letsencrypt/live/coturn.example.com/privkey.pem
Tiếp theo, chúng ta cần vô hiệu hóa lưu lượng đến các phạm vi IP riêng tư và không cho phép các đối tác trên các địa chỉ đa hướng để cải thiện bảo mật.
Mã:
# Flag that can be used to disallow peers on well-known broadcast addresses (224.0.0.0 and above, and FFXX:*).
# This is an extra security measure.
#
no-multicast-peers
...............
# Option to allow or ban specific ip addresses or ranges of ip addresses.
# If an ip address is specified as both allowed and denied, then the ip address is
# considered to be allowed. This is useful when you wish to ban a range of ip
# addresses, except for a few specific ips within that range.
#
# This can be used when you do not want users of the turn server to be able to access
# machines reachable by the turn server, but would otherwise be unreachable from the
# internet (e.g. when the turn server is sitting behind a NAT)
#
# Examples:
# denied-peer-ip=83.166.64.0-83.166.95.255
# allowed-peer-ip=83.166.68.45
denied-peer-ip=0.0.0.0-0.255.255.255
denied-peer-ip=10.0.0.0-10.255.255.255
denied-peer-ip=100.64.0.0-100.127.255.255
denied-peer-ip=127.0.0.0-127.255.255.255
denied-peer-ip=169.254.0.0-169.254.255.255
denied-peer-ip=172.16.0.0-172.31.255.255
denied-peer-ip=192.0.0.0-192.0.0.255
denied-peer-ip=192.0.2.0-192.0.2.255
denied-peer-ip=192.88.99.0-192.88.99.255
denied-peer-ip=192.168.0.0-192.168.255.255
denied-peer-ip=198.18.0.0-198.19.255.255
denied-peer-ip=198.51.100.0-198.51.100.255
denied-peer-ip=203.0.113.0-203.0.113.255
denied-peer-ip=240.0.0.0-255.255.255.255
denied-peer-ip=::1
denied-peer-ip=64:ff9b::-64:ff9b::ffff:ffff
denied-peer-ip=::ffff:0.0.0.0-::ffff:255.255.255.255
denied-peer-ip=100::-100::ffff:ffff:ffff:ffff
denied-peer-ip=2001::-2001:1ff:ffff:ffff:ffff:ffff:ffff:ffff
denied-peer-ip=2002::-2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff
denied-peer-ip=fc00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
denied-peer-ip=fe80::-febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff
Sau khi hoàn tất, hãy lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Khởi động lại Coturn để áp dụng cấu hình.
Mã:
$ sudo systemctl restart coturn
Mở tệp cấu hình Synapse (homeserver.yaml) để thêm Coturn cài đặt.
Mã:
$ nano ~/synapse/homeserver.yaml
Dán các dòng sau vào đó. Thay thế giá trị turn_shared_secret bằng giá trị của static-auth-secret từ \etc\coturn\turnserver.conf tệp.
Mã:
turn_uris: [ "turn:coturn.example.com?transport=udp", "turn:coturn.example.com?transport=tcp" ]
turn_shared_secret: 'static-auth-secret'
turn_user_lifetime: 86400000
turn_allow_guests: True
# vim:ft=yaml
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Khởi động lại Synapse để áp dụng thay đổi.
Mã:
$ sudo systemctl restart matrix-synapse

Bước 11 - Ma trận truy cập​

Bạn có thể truy cập Matrix Chat bằng trình duyệt web của Element tại https://app.element.io. Nhấp vào nút Đăng nhập để tiếp tục.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22709%22%20height=%22551%22%3E%3C/svg%3E


Nhấp vào liên kết Chỉnh sửa bên dưới Máy chủ gia đình. Nhập matrix.example.com làm máy chủ gia đình của bạn.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22514%22%20height=%22435%22%3E%3C/svg%3E


Nếu máy khách phát hiện đúng máy chủ gia đình của bạn, ranh giới và văn bản sẽ chuyển sang màu xanh lá cây, nếu không sẽ hiển thị màu đỏ. Nhấp vào Tiếp tục để tiếp tục.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22510%22%3E%3C/svg%3E


Nhập tên người dùng và mật khẩu bạn đã tạo ở bước 8 khi cấu hình Synapse. Nhấp vào nút Đăng nhập để đăng nhập. Bạn sẽ được yêu cầu tạo bản sao lưu an toàn và được mã hóa.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22606%22%20height=%22464%22%3E%3C/svg%3E


Chọn tùy chọn Nhập cụm từ bảo mật để tạo cụm từ bảo mật sẽ được yêu cầu mỗi khi bạn đăng nhập. Nhấp vào Tiếp tục để tiếp tục.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22602%22%20height=%22276%22%3E%3C/svg%3E


Nhập cụm từ bảo mật và nhấp vào nút Tiếp tục để tiếp tục. Bạn sẽ được yêu cầu xác nhận lại trên màn hình tiếp theo.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22607%22%20height=%22254%22%3E%3C/svg%3E


Nhập lại cụm từ và nhấp vào Tiếp tục để tiếp tục.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22603%22%20height=%22376%22%3E%3C/svg%3E


Bạn sẽ được cung cấp một bộ khóa bảo mật mà bạn có thể sử dụng nếu bạn quên cụm từ bảo mật của mình. Nhấp vào nút Tải xuống để lưu chúng.

Nhấp vào nút Tiếp tục để tiếp tục.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22552%22%20height=%22273%22%3E%3C/svg%3E


Bạn sẽ được yêu cầu nhập mật khẩu tài khoản của mình. Nhập mật khẩu và nhấp vào nút Tiếp tục để hoàn tất thiết lập bản sao lưu được mã hóa.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22628%22%3E%3C/svg%3E


Chúng tôi đã tạo một phòng trò chuyện nhóm có tên HowtoForge bằng cách sử dụng nút Tạo trò chuyện nhóm trên trang chủ. Bạn sẽ nhận được cửa sổ bật lên sau khi nhấp vào nút.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22499%22%20height=%22489%22%3E%3C/svg%3E


Bạn có thể hạn chế thành viên vào miền bằng cách mở rộng menu nâng cao và chọn tùy chọn. Hoàn tất việc tạo phòng bằng cách nhấp vào nút Tạo phòng.

Bước 12 - Cài đặt Element​

Tạo thư mục cho Element.
Mã:
$ sudo mkdir -p /var/www/html/element
Tạo tệp mới để lấy bản phát hành Element mới nhất.
Mã:
$ sudo nano /var/www/html/element/update.sh
Thêm các dòng sau vào đó.
Mã:
#!/bin/sh
set -e
install_location="/var/www/html/element"
latest="$(curl -I https://github.com/element-hq/element-web/releases/latest | awk -F '/' '/^location/ {print substr($NF, 1, length($NF)-1)}')"
cd "$install_location"
[ ! -d "archive" ] && mkdir -p "archive"
[ -d "archive/element-${latest}" ] && rm -r "archive/element-${latest}"
[ -f "archive/element-${latest}.tar.gz" ] && rm "archive/element-${latest}.tar.gz"
wget "https://github.com/element-hq/element-web/releases/download/${latest}/element-${latest}.tar.gz" -P "archive"
tar xf "archive/element-${latest}.tar.gz" -C "archive"
[ -L "${install_location}/current" ] && rm "${install_location}/current"
ln -sf "${install_location}/archive/element-${latest}" "${install_location}/current"
ln -sf "${install_location}/config.json" "${install_location}/current/config.json"
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Làm cho tệp có thể thực thi.
Mã:
$ sudo chmod +x /var/www/html/element/update.sh
Chạy tập lệnh để tải xuống Phần tử.
Mã:
$ sudo /var/www/html/element/update.sh

Bước 13 - Cấu hình phần tử​

Sao chép cùng một tệp cấu hình phần tử.
Mã:
$ sudo cp /var/www/html/element/current/config.sample.json /var/www/html/element/config.json
Mở tệp cấu hình để chỉnh sửa.
Mã:
$ sudo nano /var/www/html/element/config.json
Tìm các dòng sau.
Mã:
"m.homeserver": { "base_url": "https://matrix-client.matrix.org", "server_name": "matrix.org"
},
Thay đổi địa chỉ máy chủ gia đình Matrix mặc định thành máy chủ gia đình của bạn và xóa server_name biến.
Mã:
"m.homeserver": { "base_url": "https://matrix.example.com", "server_name": "example.com"
},
Nếu bạn muốn sử dụng tên của mình thay vì Element trong tiêu đề trang web, hãy thay đổi thương hiệu tên.
Mã:
"brand": "HowtoForge Example Chat",
Đặt biến disable_guests thành true để không cho phép Khách sử dụng Phần tử.
Mã:
"disable_guests": true,
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Tạo chứng chỉ SSL cho máy khách Phần tử.
Mã:
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [emailprotected] -d element.example.com
Tạo và mở tệp /etc/nginx/conf.d/element.conf để chỉnh sửa.
Mã:
$ sudo nano /etc/nginx/conf.d/element.conf
Dán các dòng sau vào nó.
Mã:
server { listen 80; listen [::]:80; server_name element.example.com; return 301 https://$host$request_uri;
}
server { listen 443 ssl; listen [::]:443 ssl; http2 on; server_name element.example.com; root /var/www/html/element/current; index index.html; access_log /var/log/nginx/element.access.log; error_log /var/log/nginx/element.error.log; add_header Referrer-Policy "strict-origin" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "SAMEORIGIN" always; # TLS configuration ssl_certificate /etc/letsencrypt/live/element.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/element.example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/element.example.com/chain.pem; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m; ssl_session_tickets off; ssl_prefer_server_ciphers on; ssl_stapling on; ssl_stapling_verify on; ssl_dhparam /etc/ssl/certs/dhparam.pem; resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] 8.8.8.8 8.8.4.4 [2001:4860:4860::8888] [2001:4860:4860::8844] valid=60s; resolver_timeout 2s; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
}
Lưu tệp bằng cách nhấn Ctrl + X và nhập Y khi được nhắc.

Xác minh cú pháp tệp cấu hình Nginx.
Mã:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Khởi động lại Nginx dịch vụ.
Mã:
$ sudo systemctl restart nginx
Chúng ta cần cấu hình cài đặt SELinux trước khi truy cập Element. Chạy các lệnh sau để cho phép Element chạy.
Mã:
$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/element(/.*)?"
$ sudo restorecon -Rv /var/www/html/element/
Bạn có thể truy cập vào máy khách Element qua URL https://element.example.com trong trình duyệt của bạn. Đăng nhập và bạn sẽ được đưa đến bảng điều khiển ứng dụng. Bạn sẽ được yêu cầu xác minh ứng dụng bằng https://app.element.io Trước tiên, hãy đảm bảo rằng bạn đã đăng nhập vào ứng dụng Element gốc và bạn sẽ được yêu cầu khớp các ký tự biểu tượng cảm xúc. Sau khi xác minh, bạn sẽ nhận được bảng thông tin sau.


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22517%22%3E%3C/svg%3E

Kết luận​

Bài hướng dẫn này kết thúc về cách cài đặt máy chủ Matrix Synapse Chat cùng với Coturn và máy khách web Element bằng cách sử dụng Nginx làm máy chủ proxy trên máy Debian 12. Nếu bạn có bất kỳ câu hỏi nào, hãy đăng chúng trong phần bình luận bên dưới.
 
Back
Bên trên