NodeBBインストール · 6 min read · Oct 14, 2025

Ubuntu 22.04にNodeBBフォーラムをインストールする方法

NodeBBは、Node.jsフレームワークによって動作する現代的なフォーラムソフトウェアです。データを保存するためにMongoDB、PostgreSQL、またはRedisデータベースを使用します。リアルタイム通知と即時インタラクションのためにWebソケットを利用しています。ソーシャルネットワーク統合、プラグインサポート、モバイル対応、完全なREST読み書きAPIなどの現代的な機能を備えています。

NodeBBは、オープンソースの自己ホスティングプロジェクトとクラウドサービスの両方として利用可能です。このチュートリアルでは、Ubuntu 22.04サーバー上でNginxを使用してNodeBBフォーラムをインストールする方法を学びます。Ubuntu 22.04はMongoDBを公式にサポートしていないため、データを保存するためにPostgreSQLを使用します。

前提条件

  • 最低1GBのRAMを搭載したUbuntu 22.04を実行しているサーバー。
  • sudo権限を持つ非rootユーザー。
  • 簡単なファイアウォール(UFW)が有効で実行中。
  • サーバーを指す完全修飾ドメイン名(FQDN)、例:forum.example.com
  • すべてが更新されていること。 $ sudo apt update && sudo apt upgrade

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

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

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

$ sudo ufw status

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

Status: active

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

HTTPおよびHTTPSポートを許可します。

$ sudo ufw allow http
$ sudo ufw allow https

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

$ sudo ufw status
Status: active

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

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

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 Sat 2022-09-10 06:25:11 UTC; 13s ago
    Process: 12083 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 12083 (code=exited, status=0/SUCCESS)
        CPU: 1ms

Sep 10 06:25:11 nodebb systemd[1]: Starting PostgreSQL RDBMS...
Sep 10 06:25:11 nodebb systemd[1]: Finished PostgreSQL RDBMS.

ステップ3 - PostgreSQLの設定

Postgresのデフォルト管理ユーザーpostgresのパスワードを設定する必要があります。まず、Postgresシェルにログインします。

$ sudo -u postgres psql

次のコマンドを入力してパスワードを変更します。

postgres=# \password postgres

新しいパスワードを求められます。

Enter new password for user "postgres":
Enter it again:

NodeBB用の新しいユーザーを作成します。

postgres=# CREATE ROLE nbbuser WITH LOGIN ENCRYPTED PASSWORD 'YourNodeBBPassword';

NodeBB用の新しいデータベースを作成します。

postgres=# CREATE DATABASE nodebbdb OWNER nbbuser;

シェルを終了するには\qと入力します。

postgres=# \q

ステップ4 - Node.jsのインストール

NodebbフォーラムはNode.jsフレームワークを使用して書かれているため、動作させるためにインストールする必要があります。

LTS(v16.x)バージョンのNodejsをインストールするために次のコマンドを発行します。

$ curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
$ sudo apt install nodejs

Node.jsとNPMのインストールを確認します。

$ node -v
v16.17.0
$ npm -v
8.15.0

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

NodeBBをインストールする前に、Gitをインストールする必要があります。次のコマンドを実行してGitをインストールします。

$ sudo apt install git

次のコマンドを実行してGitの初期設定を行います。

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

ステップ6 - NodeBBのインストール

NodeBBをrootユーザーとして実行することは推奨されません。パスワードなしの特権のないシステムユーザーを作成します。

$ sudo adduser nodebb --disabled-password

他のオプションはすべてスキップします。

NodeBBフォーラムが存在するディレクトリを作成します。

$ sudo mkdir /var/www/html/nodebb -p

フォルダの所有権を新しく作成したユーザーに変更します。

$ sudo chown -R nodebb:nodebb /var/www/html/nodebb

新しく作成したユーザーにログインします。

$ sudo su - nodebb

NodeBBインストールディレクトリに移動します。

$ cd /var/www/html/nodebb

NodeBBをインストールするには、まずそのGitHubリポジトリをクローンする必要があります。

NodeBBを/var/www/nodebbディレクトリにクローンします。コマンドの末尾のドットは現在のディレクトリを指します。

$ git clone -b v2.x https://github.com/NodeBB/NodeBB.git .

ここでは、NodeBBの最新の安定版が収められているv2.xブランチをクローンしました。NodeBBの最新の安定ブランチは、NodeBBの最新ブランチページから見つけることができます。

NodeBBにはコマンドラインユーティリティが付属しています。次のコマンドを使用してNodeBBをインストールします。

$ ./nodebb setup

デフォルト値を選択するにはEnterを押します。

2022-09-10T10:10:27.957Z [2633] - info: NodeBB Setup Triggered via Command Line

Welcome to NodeBB v2.5.2!

This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.
Press enter to accept the default setting (shown in brackets).
URL used to access this NodeBB (http://localhost:4567) https://forum.example.com
Please enter a NodeBB secret (44fd62bc-5047-4414-a4ca-83105740b624)
Would you like to submit anonymous plugin usage to nbbpm? (yes) no
Which database to use (mongo) postgres
2022-09-10T10:10:43.237Z [2633] - info:
Now configuring postgres database:
Host IP or address of your PostgreSQL instance (127.0.0.1)
Host port of your PostgreSQL instance (5432)
PostgreSQL username nbbuser
Password of your PostgreSQL database
PostgreSQL database name (nodebb) nodebbdb
Enable SSL for PostgreSQL database access (false)
........

NodeBBにアクセスするために使用するURLの値として、フォーラムにアクセスしたい最終的なURLを選択します。サーバーのIP経由でフォーラムにアクセスする場合は、それを入力するか、フォーラムの完全なドメインを入力します。ここではhttps://forum.example.comを入力します。匿名プラグイン使用の送信に関する質問にはnoと答えます。データベースタイプとしてpostgresを入力します。

次に、Enterを押してデフォルトのホストIPとポートを選択し、PostgreSQLユーザー名を入力します。これは、MongoDBの設定中にそのユーザー名のために選択したパスワードです。データベースnodebbdbを選択する必要があります。

管理者ユーザーとその詳細を作成するように求められます。

.....
2022-09-10T10:11:14.121Z [2633] - warn: No administrators have been detected, running initial user setup

Administrator username navjot
Administrator email address [email protected]
Password
Confirm Password
.....
....
2022-09-10T10:14:28.160Z [2633] - info: [build] Asset compilation successful. Completed in 118.777sec.

     =================================================================================================================================================================

NodeBB Setup Completed. Run "./nodebb start" to manually start your NodeBB server.

セットアップが完了したら、次のコマンドを実行してNodeBBを起動します。

$ ./nodebb start
Starting NodeBB
  "./nodebb stop" to stop the NodeBB server
  "./nodebb log" to view server output
  "./nodebb help" for more commands

NodeBBユーザーから退出します。

$ exit

ステップ7 - NodeBBをシステムサービスとして実行

NodeBBサービスは、システム再起動後に実行されません。NodeBBを毎回起動しないようにするために、システムサービスとしてインストールする必要があります。

まずNodeBBサービスを停止します。NodeBBディレクトリに切り替え、次のコマンドをsudo -uコマンドを使用して直接実行します。

$ cd /var/www/html/nodebb  
$ sudo -u nodebb ./nodebb stop

次のコマンドを実行してnodebb.servicesystemdユニット設定ファイルを作成および編集します。

$ sudo nano /etc/systemd/system/nodebb.service

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

[Unit]
Description=NodeBB
Documentation=https://docs.nodebb.org
After=system.slice multi-user.target postgresql.service

[Service]
Type=simple
User=nodebb

StandardError=syslog
SyslogIdentifier=nodebb

Environment=NODE_ENV=production
WorkingDirectory=/var/www/html/nodebb
ExecStart=/usr/bin/env node loader.js --no-silent --no-daemon
Restart=always

[Install]
WantedBy=multi-user.target

ここでは、ステップ6で作成したユーザー名をnodebbとして選択し、NodeBBをインストールするために選択したパスを指定しています。

NodeBBサービスを有効にします。

$ sudo systemctl enable nodebb

NodeBBサービスを開始します。

$ sudo systemctl start nodebb

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

$ sudo systemctl status nodebb
? nodebb.service - NodeBB
     Loaded: loaded (/etc/systemd/system/nodebb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-09-11 21:41:07 UTC; 2s ago
       Docs: https://docs.nodebb.org
   Main PID: 26844 (node)
      Tasks: 18 (limit: 2237)
     Memory: 94.1M
        CPU: 2.114s
     CGroup: /system.slice/nodebb.service
             ??26844 node loader.js --no-silent --no-daemon
             ??26855 /usr/bin/node /var/www/html/nodebb/app.js

Sep 11 21:41:07 forum systemd[1]: Started NodeBB.
Sep 11 21:41:07 forum nodebb[26844]: NodeBB v2.5.2 Copyright (C) 2013-2022 NodeBB Inc.
Sep 11 21:41:07 forum nodebb[26844]: This program comes with ABSOLUTELY NO WARRANTY.
Sep 11 21:41:07 forum nodebb[26844]: This is free software, and you are welcome to redistribute it under certain conditions.
Sep 11 21:41:07 forum nodebb[26844]: For the full license, please visit: http://www.gnu.org/copyleft/gpl.html
Sep 11 21:41:07 forum nodebb[26844]: Clustering enabled: Spinning up 1 process(es).
Sep 11 21:41:08 forum nodebb[26855]: 2022-09-11T21:41:08.002Z [4567/26855] - info: Initializing NodeBB v2.5.2 https://forum.example.com

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

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

ステップ9 - 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 forum.example.com

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

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

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

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

$ sudo certbot renew --dry-run

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

ステップ10 - 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/nodebb.confファイルを作成して開きます。

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

次のコードを貼り付けます。forum.example.comをあなたのドメイン名に置き換えます。フォーラムのアップロードサイズを設定するために、client_max_body_sizeの値が25MBに設定されていることを確認してください。

server {
  listen 80 default_server;
  server_name forum.example.com;
  return 301 https://$server_name$request_uri;
}

server {
   listen 443 ssl http2;
   server_name forum.example.com;

   http2_push_preload on; # Enable HTTP/2 Server Push

   ssl_certificate /etc/letsencrypt/live/forum.example.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/forum.example.com/privkey.pem;
   ssl_trusted_certificate /etc/letsencrypt/live/forum.example.com/chain.pem;
   ssl_session_timeout 1d;

   # Enable TLS versions (TLSv1.3 is required upcoming HTTP/3 QUIC).
   ssl_protocols TLSv1.2 TLSv1.3;

   # Enable TLSv1.3's 0-RTT. Use $ssl_early_data when reverse proxying to
   # prevent replay attacks.
   #
   # @see: https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data
   ssl_early_data on;

   ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384';
   ssl_prefer_server_ciphers on;
   ssl_session_cache shared:SSL:50m;

   # OCSP Stapling ---
   # fetch OCSP records from URL in ssl_certificate and cache them
   ssl_stapling on;
   ssl_stapling_verify on;
   ssl_dhparam /etc/ssl/certs/dhparam.pem;
   client_max_body_size 25M;

   gzip            on;
   gzip_min_length 1000;
   gzip_proxied    off;
   gzip_types      text/plain application/xml text/javascript application/javascript application/x-javascript text/css application/json;

   add_header X-Early-Data $tls1_3_early_data;

   location / {       
       # Socket.IO Support
       proxy_set_header Connection "upgrade";
       proxy_set_header Upgrade $http_upgrade;
       proxy_http_version 1.1;

       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-NginX-Proxy true;
       proxy_set_header X-Frame-Options SAMEORIGIN;

       proxy_pass http://127.0.0.1:4567;  # no trailing slash
       proxy_redirect off;
   }

   location @nodebb {
       proxy_pass http://127.0.0.1:4567;
   }

   location ~ ^/assets/(.*) {
       root /var/www/html/nodebb/;
       try_files /build/public/$1 /public/$1 @nodebb;
   }
}

# This block is useful for debugging TLS v1.3. Please feel free to remove this
# and use the "$ssl_early_data" variable exposed by NGINX directly should you
# wish to do so.
map $ssl_early_data $tls1_3_early_data {
  "~." $ssl_early_data;
  default "";
}

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

Nginx設定を確認します。

$ sudo nginx -t

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

$ sudo systemctl restart nginx

ステップ11 - フォーラムにアクセスして設定

ブラウザでhttps://forum.example.comのURLにアクセスすることでフォーラムにアクセスできます。次のページが表示されます。

NodeBBフォーラムホームページ

ログインページをクリックし、ステップ6で作成した管理者の資格情報を入力します。

NodeBBログインページ

ログインします。次に、メニューバーの右端のアイコンをクリックして管理パネルにアクセスします。

ここからフォーラムを管理できます。テーマやプラグインをインストールして拡張します。

NodeBBフォーラム管理ダッシュボード

テーマやプラグインをインストールした後は、管理ダッシュボードの右上隅にあるボタンを使用してフォーラムを再構築し、再起動する必要があります。

フォーラムユーザーがメールを受信できるように、ダッシュボード >> 設定 >> メールに移動してメールサービスを設定してください。最適なメール配信設定を確保するために、次の設定を選択してください。

NodeBBフォーラムメール設定

ページの下にスクロールして、ドロップダウンからカスタムメール送信者を選択するか、SMTPサービスがリストにない場合はカスタムメール送信者を使用します。このチュートリアルでは、SESサービスを使用しています。

NodeBBフォーラムSMTP設定

設定を保存するには、右下のフロッピーディスクアイコンをクリックします。

ページの下にスクロールしてテストメールを送信します。デフォルトでは、禁止されたメールテンプレートが送信されます。他のメールテンプレートを選択してテストすることもできます。歓迎メールを送信します。

NodeBBフォーラムメールテスト

設定を確認するテストメールが以下のように届きます。

NodeBBフォーラムテストメール

結論

これで、Ubuntu 22.04サーバー上でPostgreSQLデータベースとNginxを使用してNodeBBフォーラムをインストールする方法に関するチュートリアルは終了です。質問がある場合は、下のコメントに投稿してください。

Share: X/Twitter LinkedIn

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

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