Reverse Proxy Nginx on Ubuntu 20 -Adonis JS Deployment using PM2
So in this article, I’ll show you how to set up the Ubuntu 20 server from scratch, and try to deploy the Adonis JS framework as the use case using PM2 for the process manager and reverse proxy in Nginx.
- Server Environment Setup
- PM2 Ecosystem & Nginx
#1 Server Environment Setup
First thing first, let’s set up the environment by installing some required packages. For this article, I’ll be using node 16 and npm 6.
curl -sL https://deb.nodesource.com/setup_14.x -o setup_14.sh
sudo sh ./setup_14.sh
sudo apt update
sudo apt install nodejs
After the installation, we can verify the versions.
After that, let’s install the Nginx and PM2.
sudo apt install nginx
sudo npm install pm2@latest -g
#2 PM2 Ecosystem & Nginx
With that server environment being set up, let’s clone the project into the server. Usually, we put it under /var/www/html/directory.
Then, we need to build the Adonis project.
node ace build --production
Then, to make us easier for running the project using PM2, let’s utilize the PM2 ecosystem. Let’s create a new file named ecosystem.config.js under the root project.
To run the project using PM2, we can easily use our ecosystem.
pm2 start ecosystem.config.js