チャットサーバー · 7 min read · Nov 01, 2025

Ubuntu 22.04でMatrix SynapseとElementを使用してチャットサーバーをインストールおよび作成する方法

Matrixは、分散型およびエンドツーエンド暗号化通信のためのオープンスタンダードです。これは、標準化されたAPIを使用してリアルタイムで相互に通信するサーバーとサービスのコレクションです。ホームサーバーを使用してアカウント情報とチャット履歴を保存します。1つのホームサーバーがダウンしても、分散化の性質により他のサーバーは問題なく通信を続けることができます。他の誰かがホストしているMatrixホームサーバーを使用することも、自分のデータを管理するために自分自身でホストすることもできます。

このチュートリアルでは、Matrixのホームサーバー実装であるSynapseを使用してチャットサーバーをインストールおよび作成する方法を学びます。Elementは、Matrix React SDKを使用して構築されたMatrixウェブクライアントです。これにより、ウェブ上でMatrixチャットを提供できます。また、選択した他のMatrixクライアントでもサーバーを使用できます。音声およびビデオ通話を有効にするためにCoturnサーバーもインストールします。Coturnサービスは、使用することに興味がない場合はオプションです。

前提条件

  1. Ubuntu 22.04を実行しているサーバー。
  2. root権限を持つ非sudoユーザー。
  3. 簡単なファイアウォール(UFW)が有効で実行中であること。
  4. Matrix、Element、およびCoturnの完全修飾ドメイン名(FQDN)がサーバーを指していること。私たちはそれぞれの3つのサービスに対してmatrix.example.comelement.example.comcoturn.example.comを使用します。
  5. すべてが更新されていることを確認してください。 $ sudo apt update && sudo apt upgrade

ステップ1 - ファイアウォールの設定

パッケージをインストールする前に、最初のステップはHTTP、HTTPS、およびSynapseのポートを開くためにファイアウォールを設定することです。

ファイアウォールの状態を確認します。

$ sudo ufw status

次のような表示がされるはずです。

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

ファイアウォールでHTTP、HTTPS、およびSynapseのポートを開きます。

$ sudo ufw allow 8448
$ sudo ufw allow http
$ sudo ufw allow https

再度状態を確認して確認します。

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
8448                       ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443                        ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
8448 (v6)                  ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443 (v6)                   ALLOW       Anywhere (v6)

ステップ2 - Matrix Synapseのインストール

Matrix GPGキーを追加します。

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

Matrix APTリポジトリを追加します。

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

システムリポジトリリストを更新します。

$ sudo apt update

Matrix Synapseをインストールします。

$ sudo apt install matrix-synapse-py3

インストール中に、サーバー名を尋ねられます。これはMatrix IDの一部を形成します。ここにMatrixドメイン名を入力します。これがあなたのホームサーバーアドレスとして機能します。

また、ホームサーバーからMatrixに匿名化された統計を送信するかどうかを尋ねられます。拒否するにはNと入力します。

これらの設定は後で/etc/matrix-synapse/conf.d/server_name.yamlファイルで変更できます。

Matrix Synapseのサービスは、インストール中に有効化され、開始されます。サービスの状態を確認します。

$ sudo systemctl status matrix-synapse
? matrix-synapse.service - Synapse Matrix homeserver
     Loaded: loaded (/lib/systemd/system/matrix-synapse.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-09-26 09:38:38 UTC; 1min 19s ago
    Process: 12926 ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/ --generate-key>   Main PID: 12931 (python)
      Tasks: 8 (limit: 2238)
     Memory: 87.3M
        CPU: 4.180s
     CGroup: /system.slice/matrix-synapse.service
             ??12931 /opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/

Sep 26 09:38:36 matrix matrix-synapse[12926]: Generating signing key file /etc/matrix-synapse/homeserver.signing.key
Sep 26 09:38:37 matrix matrix-synapse[12931]: This server is configured to use 'matrix.org' as its trusted key server via the
Sep 26 09:38:37 matrix matrix-synapse[12931]: 'trusted_key_servers' config option. 'matrix.org' is a good choice for a key
Sep 26 09:38:37 matrix matrix-synapse[12931]: server since it is long-lived, stable and trusted. However, some admins may
Sep 26 09:38:37 matrix matrix-synapse[12931]: wish to use another server for this purpose.
Sep 26 09:38:37 matrix matrix-synapse[12931]: To suppress this warning and continue using 'matrix.org', admins should set
Sep 26 09:38:37 matrix matrix-synapse[12931]: 'suppress_key_server_warning' to 'true' in homeserver.yaml.
Sep 26 09:38:37 matrix matrix-synapse[12931]: --------------------------------------------------------------------------------
Sep 26 09:38:38 matrix matrix-synapse[12931]: Config is missing macaroon_secret_key
Sep 26 09:38:38 matrix systemd[1]: Started Synapse Matrix homeserver.

ステップ3 - PostgreSQLのインストールと設定

PostgreSQLの公式APTリポジトリを使用してインストールします。次のコマンドを実行してPostgreSQL GPGキーを追加します。

$ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-key.gpg >/dev/null

APTリポジトリをソースリストに追加します。

$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-key.gpg arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

システムリポジトリを更新します。

$ sudo apt update

次に、次のコマンドを使用してPostgreSQLをインストールできます。

$ sudo apt install postgresql postgresql-contrib

PostgreSQLサービスの状態を確認します。

$ sudo systemctl status postgresql
? postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2022-09-26 09:41:36 UTC; 2min 14s ago
    Process: 15586 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 15586 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Sep 26 09:41:36 matrix systemd[1]: Starting PostgreSQL RDBMS...
Sep 26 09:41:36 matrix systemd[1]: Finished PostgreSQL RDBMS.

サービスがデフォルトで有効になり、実行中であることがわかります。

postgresシステムアカウントにログインします。

$ sudo -su postgres

新しいデータベースユーザーとデータベースをPostgreSQL用に作成します。

$ createuser --pwprompt synapse
$ createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse synapse

postgresアカウントから退出します。

$ exit

ステップ4 - Nginxのインストール

本番環境では、Nginxプロキシを使用してSynapseサーバーを実行することをお勧めします。

Ubuntu 22.04には古いバージョンのNginxが付属しています。最新バージョンをインストールするには、公式のNginxリポジトリをダウンロードする必要があります。

Nginxの署名キーをインポートします。

$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Nginxの安定版のリポジトリを追加します。

$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list

システムリポジトリを更新します。

$ sudo apt update

Nginxをインストールします。

$ sudo apt install nginx

インストールを確認します。

$ nginx -v
nginx version: nginx/1.22.0

Nginxサーバーを起動します。

$ sudo systemctl start nginx

ステップ5 - SSLのインストール

SSL証明書を生成するためにCertbotをインストールする必要があります。Ubuntuのリポジトリを使用してCertbotをインストールするか、Snapdツールを使用して最新バージョンを取得できます。Snapdバージョンを使用します。

Ubuntu 22.04にはデフォルトでSnapdがインストールされています。次のコマンドを実行してSnapdのバージョンが最新であることを確認します。

$ sudo snap install core
$ sudo snap refresh core

Certbotをインストールします。

$ sudo snap install --classic certbot

次のコマンドを使用して、Certbotコマンドが/usr/binディレクトリにシンボリックリンクを作成することで実行できることを確認します。

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

次のコマンドを実行してSSL証明書を生成します。

$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email protected] -d matrix.example.com

上記のコマンドは、サーバーの/etc/letsencrypt/live/matrix.example.comディレクトリに証明書をダウンロードします。

Diffie-Hellmanグループ証明書を生成します。

$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096

SSL更新が正常に機能しているかどうかを確認するために、プロセスのドライランを行います。

$ sudo certbot renew --dry-run

エラーが表示されない場合は、すべて設定完了です。証明書は自動的に更新されます。

ステップ6 - Matrix Synapseの設定

Matrixサーバーは/etc/matrix-synapse/homeserver.yamlファイルを介して設定できますが、アップグレードのたびに上書きされるため推奨されません。本番環境では、設定ファイルを/etc/matrix-synapse/conf.dフォルダーに配置する必要があります。

Synapseのインストールにより、/etc/matrix-synapse/conf.dフォルダーに2つの設定ファイルが作成されました。

$ ls /etc/matrix-synapse/conf.d
report_stats.yaml  server_name.yaml

データベース用の新しい設定ファイルを作成し、編集のために開きます。

$ sudo nano /etc/matrix-synapse/conf.d/database.yaml

エディターに次の行を貼り付けます。your-passwordフィールドをステップ3で作成したPostgreSQLユーザーのパスワードに置き換えます。データベースを別の場所にホストしている場合は、localhostをサーバーのIPアドレスに置き換えます。

database:
  name: psycopg2
  args:
    user: synapse
    password: 'your-password'
    database: synapsedb
    host: localhost
    cp_min: 5
    cp_max: 10

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

秘密の登録キーを作成します。このキーは、新しいユーザーを登録することを許可するために保護されるべきです。登録が無効になっていても、誰でも新しいユーザーを登録できます。

$ echo "registration_shared_secret: '$(cat /dev/urandom | tr -cd '[:alnum:]' | fold -w 256 | head -n 1)'" | sudo tee /etc/matrix-synapse/conf.d/registration_shared_secret.yaml

デフォルトでは、Synapseは人がオンラインであるかどうかを示すプレゼンスインジケーターを有効にします。これによりCPU使用率が高くなる可能性があるため、無効にすることができます。同じための新しい設定ファイルを作成します。

$ sudo nano /etc/matrix-synapse/conf.d/presence.yaml

エディターに次の行を貼り付けます。

presence:
  enabled: false

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

変更を適用するためにSynapseサービスを再起動します。

新しいMatrixユーザーを作成します。ユーザー名とパスワードを尋ねられます。これは最初に作成するユーザーなので、ユーザーを管理者にするかどうか尋ねられたときにyesと入力します。

$ register_new_matrix_user -c /etc/matrix-synapse/conf.d/registration_shared_secret.yaml http://localhost:8008
New user localpart [navjot]: navjot
Password: 
Confirm password: 
Make admin [no]: yes
Sending registration request...
Success!

公開登録を開く場合は、新しい設定ファイルを作成します。

$ sudo nano /etc/matrix-synapse/conf.d/registration.yaml

次の行を貼り付けます。

enable_registration: true

デフォルトでは、Synapseはメール確認なしでの登録を許可しません。メール確認を有効にするには、次の行を貼り付けます。

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: '[email protected]'
  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 <[email protected]>"

メール確認を無効にするには、代わりに次の行を貼り付けます。

enable_registration_without_verification: true

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

設定を適用するためにSynapseを再起動します。

$ sudo systemctl restart matrix-synapse

ステップ7 - Nginxの設定

/etc/nginx/nginx.confファイルを編集のために開きます。

$ sudo nano /etc/nginx/nginx.conf

include /etc/nginx/conf.d/*.conf;の前に次の行を追加します。

server_names_hash_bucket_size  64;

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

/etc/nginx/conf.d/synapse.confファイルを作成して開きます。

$ sudo nano /etc/nginx/conf.d/synapse.conf

次のコードを貼り付けます。

# 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 http2;
    listen [::]:443 ssl http2;

    # Federation port
    listen 8448 ssl http2 default_server;
    listen [::]:8448 ssl http2 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_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers 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;
    }
}

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

Nginx設定ファイルの構文を確認します。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginxサービスを再起動します。

$ sudo systemctl restart nginx

ステップ8 - Coturnのインストール

音声およびビデオ通話を有効にするために、NATの周りでリレーを使用するトラバーサル(TURN)サーバーをインストールする必要があります。この目的のために、Coturnパッケージをインストールします。この機能が必要ない場合は、このステップをスキップできます。

Ubuntu 22.04にはCoturnパッケージが付属していませんが、バグの問題が解決されたためです。ただし、非公式のリポジトリを使用してCoturnをインストールする別の方法があります。オプションとしてDockerを使用してCoturnをインストールすることもできますが、このチュートリアルの範囲外のため、その方法は使用しません。

非公式のCoturnリポジトリを追加します。

$ sudo add-apt-repository ppa:ubuntuhandbook1/coturn

Coturnをインストールします。

$ sudo apt install coturn

TURNおよびUDPポートを開きます。

$ sudo ufw allow 3478
$ sudo ufw allow 5349
$ sudo ufw allow 49152:65535/udp

Turn(turn.example.com)のSSL証明書を生成します。

$ sudo certbot certonly --nginx -d turn.example.com

認証シークレットを生成し、設定ファイルに保存します。

$ echo "static-auth-secret=$(cat /dev/urandom | tr -cd '[:alnum:]' | fold -w 256 | head -n 1)" | sudo tee /etc/turnserver.conf

設定ファイルを編集のために開きます。

$ sudo nano /etc/turnserver.conf

認証シークレットの下に次の行を貼り付けます。

use-auth-secret
realm=turn.example.com
cert=/etc/letsencrypt/live/turn.example.com/fullchain.pem
pkey=/etc/letsencrypt/live/turn.example.com/privkey.pem

# VoIP is UDP, no need for TCP
no-tcp-relay

# Do not allow traffic to private IP ranges
deno-multicast-peers
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

# Limit number of sessions per user
user-quota=12
# Limit total number of sessions
total-quota=1200

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

構成を適用するためにCoturnを再起動します。

$ sudo systemctl restart coturn

Coturn用の新しいSynapse設定ファイルを作成します。

$ sudo nano /etc/matrix-synapse/conf.d/turn.yaml

次の行を貼り付けます。turn_shared_secret値を/etc/turnserver.confファイルのstatic-auth-secretの値に置き換えます。

turn_uris: [ "turn:turn.example.com?transport=udp", "turn:turn.example.com?transport=tcp" ]
turn_shared_secret: 'static-auth-secret'
turn_user_lifetime: 86400000
turn_allow_guests: True

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

変更を適用するためにSynapseを再起動します。

$ sudo systemctl restart matrix-synapse

ステップ9 - Matrixにアクセス

Elementのウェブクライアントを使用してMatrixチャットにアクセスできます。https://app.element.ioにアクセスします。サインインボタンをクリックして進みます。

Element Web Login Page

ホームサーバーの下にある編集リンクをクリックします。matrix.example.comをホームサーバーとして入力します。

Element Client Custom Homeserver

クライアントがホームサーバーを正しく検出すると、境界とテキストが緑色になります。そうでない場合は赤色で表示されます。続行をクリックして進みます。

Element Custom Homeserver Login

サインインボタンをクリックしてログインします。安全で暗号化されたバックアップを作成するように求められます。

Matrix Secure Backup

セキュリティフレーズを入力オプションを選択して、ログインするたびに必要なセキュリティフレーズを作成します。続行をクリックして進みます。

Element Security Phrase

セキュリティフレーズを入力し、続行ボタンをクリックして進みます。次の画面で再度確認を求められます。

Element Confirm Security Phrase

再度フレーズを入力し、続行をクリックして進みます。

Element Security Key Poup

セキュリティフレーズを忘れた場合に使用できる一連のセキュリティキーが提供されます。ダウンロードボタンをクリックして保存します。

続行ボタンをクリックして進みます。

Element Password Verify

アカウントのパスワードを求められます。パスワードを入力し、続行ボタンをクリックして暗号化バックアップの設定を完了します。

Element Web Client Dashboard

上記のように、Howtoforgeという名前のグループチャットルームを作成しました。

ステップ10 - Elementのインストール

JSONテキストプロセッサをインストールするためにjqパッケージをインストールします。

$ sudo apt install jq

Element用のディレクトリを作成します。

$ sudo mkdir -p /var/www/element

最新のElementリリースを取得するための新しいファイルを作成します。

$ sudo nano /var/www/element/update.sh

次の行を追加します。

#!/bin/sh
set -e

install_location="/var/www/element"
latest="
$(curl -s https://api.github.com/repos/vector-im/element-web/releases/latest | jq -r .tag_name)
"

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/vector-im/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"

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

ファイルを実行可能にします。

$ sudo chmod +x /var/www/element/update.sh

Elementをダウンロードするためにスクリプトを実行します。

$ sudo /var/www/element/update.sh

ステップ11 - Elementの設定

同じElement設定ファイルをコピーします。

$ sudo cp /var/www/element/current/config.sample.json /var/www/element/config.json

設定ファイルを編集のために開きます。

$ sudo nano /var/www/element/config.json

次の行を見つけます。

"m.homeserver": {
    "base_url": "https://matrix-client.matrix.org",
    "server_name": "matrix.org"
},

デフォルトのMatrixホームサーバーアドレスをホームサーバーに変更し、server_name変数を削除します。

"m.homeserver": {
    "base_url": "https://matrix.example.com",
    "server_name": "matrix.element.com"  
},

ウェブサイトのタイトルにElementの代わりに自分の名前を使用したい場合は、ブランド名を変更します。

"brand": "Howtoforge Example Chat",

ゲストがElementを使用することを禁止するために、disable_guests変数をtrueに設定します。

"disable_guests": true,

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

Elementクライアント用のSSL証明書を生成します。

$ sudo certbot certonly --nginx -d element.example.com

/etc/nginx/conf.d/element.confファイルを作成して編集のために開きます。

$ sudo nano /etc/nginx/conf.d/element.conf

次の行を貼り付けます。

server {
    listen 80;
    listen [::]:80;
    server_name element.example.com;
    return 301 https://$host$request_uri;
}

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

    server_name element.example.com;

    root /var/www/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_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
}

Ctrl + Xを押してファイルを保存し、プロンプトが表示されたらYを入力します。

Nginx設定ファイルの構文を確認します。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Nginxサービスを再起動します。

$ sudo systemctl restart nginx

ブラウザでhttps://element.example.comにアクセスしてElementクライアントにアクセスできます。ログインすると、アプリダッシュボードに移動します。

Element Self-Hosted Dashboard

結論

これで、Nginxをプロキシサーバーとして使用してMatrix SynapseチャットサーバーとCoturnおよびElementウェブクライアントをインストールする方法に関するチュートリアルが終了します。質問がある場合は、下のコメントに投稿してください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。