GNU/Linux >> Linux の 問題 >  >> Cent OS

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

Sails.jsは、Node.js用のJavascriptフレームワークです。これは、リアルタイムアプリケーションを非常に迅速に開発するために使用されます。これにより、RubyonRailsなどのフレームワークのMVCアーキテクチャに似せることができます。コードを記述せずにアプリのバックエンドをジャンプスタートするのに役立つブループリントが付属しています。 Angular、React、iOS、Android、Windows Phone、カスタムハードウェア、またはその他のものを含む他のフロントエンドと完全に互換性があります。

この投稿では、CentOS8にNginxを使用してSails.jsをインストールする方法を紹介します

前提条件
  • CentOS8を実行しているサーバー。
  • ルートパスワードはサーバーで構成されています。

Node.jsをインストール

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

dnf install curl gcc-c++ make -y

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

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  ·  Extensible project with auth, login, & password recovery
 2. Empty    ·  An empty Sails app, yours to configure
 (type "?" for help, or <CTRL+C> to cancel)
? 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

次のコマンドでセイルのステータスを確認できます:

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でリッスンしています。

NginxをSailsアプリケーションのリバースプロキシとして構成する

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

まず、次のコマンドを使用して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を確認します。

nginx -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がファイアウォールを通過できるようにする必要があります。次のコマンドで許可できます:

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

次に、ファイアウォールをリロードして変更を適用します。

firewall-cmd --reload

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

Sails.jsWebインターフェースにアクセス

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

結論

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


Cent OS
  1. CentOS7にngx_pagespeedを使用してNginxをインストールします

  2. CentOS 7 /RHEL7にNginxを使用してphpMyAdminをインストールする方法

  3. CentOS7にSails.jsをインストールします

  1. CentOS7にNginxを使用してWordPressをインストールする方法

  2. CentOS7にNginxを使用してphpMyAdminをインストールする方法

  3. CentOS7にNginxを使用してSuiteCRMをインストールする方法

  1. CentOS7にNginxでMediaWikiをインストールする方法

  2. CentOS7にNginxを使用してSeafileをインストールする方法

  3. CentOS7にNginxを使用してRedmine3をインストールする方法