Reverse Proxy Nginx on Ubuntu 20 -Adonis JS Deployment using PM2

Cerwyn Cahyono
3 min readJan 4, 2022
https://www.nginx.com

Nginx is one of the most popular web servers in the world today, besides the Apache. One of the reasons Nginx is popular is because it’s very lightweight and has a better performance at handling a lot of connections at the same time. Also, deploying a Javascript app (that’s also a popular technology these days) using the reverse proxy is very straightforward and simple

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.

Content Overview

  • 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.

node -v
npm -v

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

--

--

Cerwyn Cahyono

PHP/Backend Engineer at Undercurrent Capital Pte Ltd — Data Science Enthusiast