云计算百科
云计算领域专业知识百科平台

搭建一个局域网通信服务器matrix-synapse

前言

搭建一个matrix-synapse服务器,用于客户端在局域网内实现文字,语音和视频交流,以及文件上传。要支持广域网需要更多步骤,暂不实现。

搭建步骤

在此之前,需要准备好nginx和域名服务器,以及签名证书。

安装matrix-synapse服务

  • 下载软件包 https://github.com/matrix-org/synapse/releases 选择最新版本,下载debs.tar.xz并解压
  • 安装系统对应的软件包,比如ubuntu22.04 apt install ./matrix-synapse-py3_1.130.0+jammy1_amd64.deb apt install -f
  • 启动服务 systemctl enable matrix-synapse systemctl start matrix-synapse systemctl status matrix-synapse
  • 测试服务是否运行 浏览器打开 http://localhost:8008/_matrix/static/

配置服务

matrix的大部分配置都存在于 /etc/matrix-synapse/homeserver.yaml

  • 服务监听配置

listeners:
– port: 8008
tls: false
type: http
x_forwarded: true
bind_addresses: ['127.0.0.1']
resources:
– names: [client, federation]
compress: false

  • 注册配置

enable_registration: true
registration_shared_secret: "d5568162173f2377a5e9c4a8ad69c31c"
registration_requires_token: false
enable_registration_without_verification: true

配置项分别是允许注册,注册共享密钥,不要求token,允许不经过验证就注册 密钥随便生成一个字符串就行 openssl rand -hex 16 注册配置生效后,添加一个管理员账号 register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml http://localhost:8008

  • 文件上传配置

media_store_path: /var/lib/matrix-synapse/media
max_upload_size: 1073741824 # 1024MB
enable_media_repo: true

见名只意

nginx代理https服务

在nginx的站点配置目录 /etc/nginx/sites-available 新增一个文件,比如 matrix,添加如下内容:

server {
listen 443 ssl;
server_name matrix.example.com;

ssl_certificate /etc/ssl/matrix/cert.pem;
ssl_certificate_key /etc/ssl/matrix/key.pem;

location /.well-known/matrix/client {
add_header Content-Type application/json;
return 200 '{"m.homeserver": {"base_url": "https://matrix.example.com"}}';
}

location /.well-known/matrix/server {
add_header Content-Type application/json;
return 200 '{"m.server": "matrix.example.com:443"}';
}

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

location /_matrix/media/ {
proxy_pass http://localhost:8008;
client_max_body_size 1024M;
}
}

其实服务名可自定义,这里是matrix.example.com,ssl需要的签名证书可以自己本地生成。之后使能站点配置,进入目录 /etc/nginx/sites-enabled,执行命令 ln -s /etc/nginx/sites-available/matrix matrix 之后重载nginx配置。 在windows上安装了证书,并配置域名之后,浏览器分别输入: https://matrix.example.com/.well-known/matrix/client https://matrix.example.com/.well-known/matrix/server https://matrix.example.com/_matrix/federation/v1/version 能返回结果就表示成功了

安装客户端

matrix-synapse有很多客户端,这里以element客户端为例简单介绍下。

  • 下载element客户端,支持android,ios,Windows,linux等多种系统 https://element.io/app
  • 安装后打开客户端,保证与服务器的网络畅通,服务器地址选择matrix.example.com
  • 注册账号,登录
  • 试试聊天,音视频通话,文件上传

后话

本文介绍了最简单的matrix服务器怎么安装配置,关于更详细的说明,以及更复杂的功能,参见官方说明文档 https://matrix-org.github.io/synapse/latest,如果我想起来,会继续更新一下。

赞(0)
未经允许不得转载:网硕互联帮助中心 » 搭建一个局域网通信服务器matrix-synapse
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!