Sails.js は、Node.js 向けの人気のある無料のオープンソース MVC フレームワークです。 シンプルで使いやすく、Node.js 環境の上で開発されました。 開発者は、カスタムおよびエンタープライズ グレードの Node.js アプリケーションを簡単に構築できます。 Sails.js は、開発者が少ないコードでアプリケーションを構築するのに役立つコード ジェネレーターを提供します。 Sails.js を使用すると、チャット、リアルタイム ダッシュボード、およびマルチプレイヤー ゲームを開発できます。
この投稿では、Oracle Linux 8 に Nginx を使用して Salis.js フレームワークをインストールする方法を紹介します。
前提条件
- Your self Cloud Platform で Oracle Linux 8 を実行するサーバー
- サーバーで設定された root パスワード
ステップ 1 – 自分のクラウド サーバーを作成する
まず、あなたのあなた自身のクラウドサーバー. 少なくとも 2GB の RAM を備えたオペレーティング システムとして Oracle Linux 8 を選択して、新しいサーバーを作成します。 SSH 経由でクラウド サーバーに接続し、ページの上部で強調表示されている資格情報を使用してログインします。
サーバーにログインしたら、次のコマンドを実行して、基本システムを最新の利用可能なパッケージで更新します。
dnf update -y
ステップ 2 – Node.js を Oracle Linux 8 にインストールする
まず、システムに Node.js をインストールする必要があります。 これを行うには、まず次のコマンドを使用して、必要なすべての依存関係をインストールします。
dnf install curl gcc-c++ make -y
次に、次のコマンドを使用して Node ソース リポジトリを追加します。
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
次に、次のコマンドを実行して Node.js をインストールします。
dnf install nodejs -y
Node.js がインストールされたら、次のコマンドを使用して Node.js のバージョンを確認できます。
node --version
次の出力が得られます。
v18.4.0
ステップ 3 – Sails.js を Oracle Linux 8 にインストールする
NPM を使用して、Sails.js をシステムに簡単にインストールできます。 次のコマンドを実行して、NPM コマンドを使用して Sail.js をインストールしましょう。
npm -g install sails
Sails.js のインストール後、Sails.js アプリケーション用のディレクトリを作成します。
mkdir sails
次に、ディレクトリを帆に変更し、次のコマンドを使用して新しいアプリケーションを作成します。
cd sails sails new newapp
アプリケーションのテンプレートを選択するよう求められます。
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) ? 1
1 を入力して Enter キーを押し、アプリケーションを作成します。
info: Installing dependencies... Press CTRL+C to cancel. (to skip this step in the future, use --fast) info: Created a new Sails app `newapp`!
ステップ 4 – Sails.js アプリケーションを開始する
Sails.js アプリケーションを作成したら、ディレクトリをアプリケーションに変更し、以下のコマンドを使用してアプリケーションを起動します。
cd newapp sails lift
次の出力が得られます。
info: Starting app... info: Initializing project hook... (`api/hooks/custom/`) info: Initializing `apianalytics` hook... (requests to monitored routes will be logged!) info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. info: ✓ Auto-migration complete. debug: Running v0 bootstrap script... (looks like this is the first time the bootstrap has run on this computer) info: info: .-..-. info: info: Sails <| .-..-. info: v1.5.2 | info: /|. info: / || info: ,' |' info: .-'.-==|/_--' info: `--'-------' info: __---___--___---___--___---___--___ info: ____---___--___---___--___---___--___-__ info: info: Server lifted in `/root/sails/newapp` info: To shut down Sails, press + C at any time. info: Read more at https://sailsjs.com/support. debug: ------------------------------------------------------- debug: :: Tue Jun 28 2022 11:52:10 GMT-0400 (Eastern Daylight Time) debug: Environment : development debug: Port : 1337 debug: -------------------------------------------------------
CTRL+C を押して、アプリケーションを停止します。
ステップ 5 – Salis.js 用の Systemd サービス ファイルを作成する
Sails.js アプリケーションを管理するための systemd サービス ファイルを作成することをお勧めします。 次のコマンドを使用して作成できます。
nano /lib/systemd/system/sails.service
次の行を追加します。
[Unit] After=network.target [Service] Type=simple User=root WorkingDirectory=/root/sails/newapp ExecStart=/usr/bin/sails lift Restart=on-failure [Install] WantedBy=multi-user.target
ファイルを保存して閉じ、systemd デーモンをリロードして変更を適用します。
systemctl daemon-reload
ここで、Sails.js サービスを開始し、システムの再起動時に開始できるようにします。
systemctl start sails systemctl enable sails
次のコマンドを使用して、Sails.js サービスのステータスを確認することもできます。
systemctl status sails
次の出力が得られます。
● sails.service Loaded: loaded (/usr/lib/systemd/system/sails.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2022-06-28 11:53:20 EDT; 6s ago Main PID: 18809 (node) Tasks: 22 (limit: 11409) Memory: 147.9M CGroup: /system.slice/sails.service ├─18809 node /usr/bin/sails lift └─18816 grunt Jun 28 11:53:24 oraclelinux8 sails[18809]: info: ____---___--___---___--___---___--___-__ Jun 28 11:53:24 oraclelinux8 sails[18809]: info: Jun 28 11:53:24 oraclelinux8 sails[18809]: info: Server lifted in `/root/sails/newapp` Jun 28 11:53:24 oraclelinux8 sails[18809]: info: To shut down Sails, press + C at any time. Jun 28 11:53:24 oraclelinux8 sails[18809]: info: Read more at https://sailsjs.com/support. Jun 28 11:53:24 oraclelinux8 sails[18809]: debug: ------------------------------------------------------- Jun 28 11:53:24 oraclelinux8 sails[18809]: debug: :: Tue Jun 28 2022 11:53:24 GMT-0400 (Eastern Daylight Time) Jun 28 11:53:24 oraclelinux8 sails[18809]: debug: Environment : development Jun 28 11:53:24 oraclelinux8 sails[18809]: debug: Port : 1337 Jun 28 11:53:24 oraclelinux8 sails[18809]: debug: -------------------------------------------------------
この時点で、Sails.js アプリケーションが開始され、ポート 1337 でリッスンします。次のコマンドを使用して確認できます。
ss -antpl | grep 1337
次の出力が得られます。
LISTEN 0 128 *:1337 *:* users:(("node",pid=18809,fd=19))
ステップ 6 – Nginx を Sails.js のリバース プロキシとして構成する
まず、次のコマンドで Nginx をインストールします。
dnf install nginx
次に、次のコマンドを使用して Nginx 仮想ホスト構成ファイルを作成します。
nano /etc/nginx/conf.d/sails.conf
次の行を追加します。
server { listen 80; server_name sails.example.com; location / { proxy_pass https://localhost:1337/; proxy_set_header Host $host; proxy_buffering off; } }
ファイルを保存して閉じ、Nginx のメイン構成ファイルを編集します。
nano /etc/nginx/nginx.conf
最大ハッシュ バケット サイズを定義します。
server_names_hash_bucket_size 64;
次に、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 restart nginx
ステップ 7 – Sails.js にアクセスする
ここで、Web ブラウザーを開き、URL を使用して Sails.js Web インターフェースにアクセスします。https://sails.example.com. 次の画面に Sails.js アプリケーションが表示されます。
結論
この投稿では、Oracle Linux 8 に Nginx を使用して Sails.js をインストールする方法について説明しました。これで、Sails.js フレームワークを使用して最初のリアルタイム アプリケーションの開発を開始できます。 あなた自身の専用ホスティングで試してみてください!