How To Use Apache as a Reverse Proxy with mod_proxy on Ubuntu 22.04
a month ago
Step 1 : Install PM2 Using NPM
Use the NPM package manager to install PM2 by entering the following command in the terminal:
npm install pm2 -g
Step 2 : Generate a PM2 Start Script for the Init System:
PM2 is designed to operate with the default init system on a Linux system (which it can automatically detect) to produce the startup script and set up PM2 as a service that can then be restarted at system boot. Simply execute the following command as root to generate the startup script:
pm2 startup
Step 3 : Build Node.js App
Create a new file with the name app.js in your chosen text editor. Copy and paste the following command into the file:
const http = require('http');
const hostname = '0.0.0.0';
const port = 80;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Save the file and exit.
Step 3 : Start Node JS Application Using PM2
Run the following command in the terminal to launch a Node JS application using PM2:
pm2 start app.js
Keep in mind that when we start an application, we may also use the following extra parameters:
Go visit the official documentation to see all available parameters.
Step 4 : Manage the Application
Let's use the following commands in the terminal to restart, reload, stop, and delete operational processes in the Node JS application using PM2:
pm2 restart app
pm2 reload app
pm2 stop app
pm2 delete app
The tutorial allows anyone to quickly and effectively learn the processes of the installation and configuration of PM2 on Ubuntu 22.04.