インストールガイド · 2 min read · Oct 31, 2025

CentOS 8にNginxを使用してSails.jsフレームワークをインストールする

Sails.jsはNode.js用のJavascriptフレームワークです。リアルタイムアプリケーションを非常に迅速に開発するために使用されます。Ruby on RailsのようなフレームワークからMVCアーキテクチャを模倣することができます。コードを書くことなくアプリのバックエンドを迅速に立ち上げるのに役立つブループリントが付属しています。Angular、React、iOS、Android、Windows Phone、カスタムハードウェア、またはまったく別のものを含む他のフロントエンドと互換性があります。

この記事では、CentOS 8にNginxを使用してSails.jsをインストールする方法を示します。

前提条件

  • CentOS 8を実行しているサーバー。
  • サーバーに設定されたrootパスワード。

Node.jsのインストール

まず、次のコマンドを使用して必要な依存関係をすべてインストールします:

dnf install curl gcc-c++ make -y

すべての依存関係がインストールされたら、次のコマンドを使用してNodeソースリポジトリを追加します:

curl -sL https://rpm.nodesource.com/setup_16.x | bash -

Nodeソースリポジトリを追加した後、次のコマンドを使用してNode.jsをインストールします:

dnf install nodejs -y

インストールが完了したら、次のコマンドを使用してNode.jsのバージョンを確認します:

node --version

次の出力が得られるはずです:

v16.4.0

Sails.jsのインストール

次のようにNPMコマンドを使用してSails.jsをインストールできます:

npm -g install sails

次に、次のコマンドを使用してSails.jsでプロジェクトを作成します:

sails new myproject

アプリケーションのテンプレートを選択するように求められます:

 Choose a template for your new Sails app:
 1. Web App  ·  認証、ログイン、パスワード回復を備えた拡張可能なプロジェクト
 2. Empty    ·  設定可能な空のSailsアプリ
 (ヘルプが必要な場合は「?」を入力、またはでキャンセル)
? 2

2を入力してEnterを押してアプリケーションをインストールします。次の出力が得られるはずです:

 info: Installing dependencies...
Press CTRL+C to cancel.
(to skip this step in the future, use --fast)

 info: Created a new Sails app `myproject`!

Sails.jsアプリケーションの起動

次に、myprojectディレクトリに移動し、次のコマンドを使用してアプリケーションを起動します:

cd myproject  
sails lift

次の出力が得られるはずです:

 info: Starting app...

 info: 
 info:                .-..-.
 info: 
 info:    Sails              <|    .-..-.
 info:    v1.4.3              |\
 info:                       /|.\
 info:                      / || \
 info:                    ,'  |'  \
 info:                 .-'.-==|/_--'
 info:                 `--'-------' 
 info:    __---___--___---___--___---___--___
 info:  ____---___--___---___--___---___--___-__
 info: 
 info: Server lifted in `/root/myproject`
 info: To shut down Sails, press  + C at any time.
 info: Read more at https://sailsjs.com/support.

debug: -------------------------------------------------------
debug: :: Thu Jun 24 2021 04:46:13 GMT-0400 (Eastern Daylight Time)

debug: Environment : development
debug: Port        : 1337
debug: -------------------------------------------------------

CTRL + Cを押してアプリケーションを停止します。

Sails.jsのためのSystemdサービスファイルの作成

次に、アプリケーションを管理するためのsystemdサービスファイルを作成する必要があります。

次のコマンドを使用して作成できます:

nano /lib/systemd/system/sails.service

次の行を追加します:

[Unit]
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/myproject
ExecStart=/usr/bin/sails lift
Restart=on-failure

[Install]
WantedBy=multi-user.target

ファイルを保存して閉じたら、次のコマンドを使用してsystemdデーモンをリロードします:

systemctl daemon-reload

次に、Sailsサービスを起動し、システム再起動時に自動的に起動するように設定します:

systemctl start sails  
systemctl enable sails

次のコマンドを使用してSailsのステータスを確認できます:

systemctl status sails

次の出力が得られるはずです:

? sails.service
   Loaded: loaded (/usr/lib/systemd/system/sails.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-06-24 04:47:07 EDT; 5s ago
 Main PID: 47388 (node)
    Tasks: 22 (limit: 25014)
   Memory: 148.1M
   CGroup: /system.slice/sails.service
           ??47388 node /usr/bin/sails lift
           ??47395 grunt

Jun 24 04:47:09 centos8 sails[47388]:  info:  ____---___--___---___--___---___--___-__
Jun 24 04:47:09 centos8 sails[47388]:  info:
Jun 24 04:47:09 centos8 sails[47388]:  info: Server lifted in `/root/myproject`
Jun 24 04:47:09 centos8 sails[47388]:  info: To shut down Sails, press  + C at any time.
Jun 24 04:47:09 centos8 sails[47388]:  info: Read more at https://sailsjs.com/support.
Jun 24 04:47:09 centos8 sails[47388]: debug: -------------------------------------------------------
Jun 24 04:47:09 centos8 sails[47388]: debug: :: Thu Jun 24 2021 04:47:09 GMT-0400 (Eastern Daylight Time)
Jun 24 04:47:09 centos8 sails[47388]: debug: Environment : development
Jun 24 04:47:09 centos8 sails[47388]: debug: Port        : 1337
Jun 24 04:47:09 centos8 sails[47388]: debug: -------------------------------------------------------

この時点で、Sailsは起動し、ポート1337でリッスンしています。

SailsアプリケーションのためのNginxをリバースプロキシとして設定

SailsアプリケーションへのリバースプロキシとしてNginxをインストールして設定することをお勧めします。

まず、次のコマンドを使用してNginxパッケージをインストールします:

dnf install nginx -y

Nginxをインストールした後、SailsのためのNginx仮想ホスト設定ファイルを作成します:

nano /etc/nginx/conf.d/sails.conf

次の行を追加します:

server {
 listen       80;
 server_name  sails.domain.com;
   location / {
     proxy_pass        http://localhost:1337/;
     proxy_set_header  Host $host;
     proxy_buffering   off;
   }
 }

作業が完了したら、ファイルを保存して閉じます。

次に、次のコマンドを使用してNginxの設定エラーを確認します:

ginx -t

次の出力が得られるはずです:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

次に、Nginxサービスを起動し、システム再起動時に自動的に起動するように設定します:

systemctl start nginx  
systemctl enable nginx

次のコマンドを使用してNginxサービスのステータスを確認します:

systemctl status nginx

ファイアウォールの設定

次に、ファイアウォールを通過するポート80を許可する必要があります。次のコマンドを使用して許可できます:

firebase-cmd --permanent --zone=public --add-port=80/tcp

次に、変更を適用するためにファイアウォールをリロードします:

firebase-cmd --reload

作業が完了したら、次のステップに進むことができます。

Sails.jsウェブインターフェースにアクセス

今、ウェブブラウザを開き、URL http://salis.domain.comを使用してSails.jsウェブインターフェースにアクセスします。次の画面にSails.jsのデフォルトページが表示されるはずです:

Sails.js

結論

おめでとうございます!Nginxをリバースプロキシとして使用してCentOS 8にSails.jsを正常にインストールしました。これで、Sailsを使用してリアルタイムアプリケーションの開発を開始できます。

Share: X/Twitter LinkedIn

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

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