
Deploy on VPS with Nginx, PM2 and SSL
In this blog, we will confidently guide you through deploying on a VPS server, setting up the environment, and configuring your domain.
Get your VPS Hosting from Hostinger today!
- Click here to secure India’s best hosting 👉 VPS Hosting
- Dynamic Coding with Amit Family 💥, take advantage of the discount code DCA10 for an immediate 10% off!
- After completing your payment, you will be redirected to the homepage. Click on "Start" without hesitation.


Setup
- Select the VPS location that is closest to your target audience. it will help you to reduce latency and improve the speed of your website. Click to .
Select Operating System
- Select your operating system. Hostinger is a greater choice for beginners as well as professionals there is three section Plan OS , OS with Panel and Applications are available.
- Designed specifically for advanced users who are proficient with command-line interfaces and adept at configuring custom setups.
- Ensure the manual installation of essential applications and services, including Apache, Nginx, MySQL, Node.js, MongoDB, pm2, WordPress, and more.
Plan OS:
- Perfect for users who demand a hassle-free hosting environment with minimal manual setup.
- A hosting control panel offers a graphical user interface (GUI) that allows users to manage applications, databases, domains, and files.
- Popular Control Panels cPanel, Plesk, Hostinger’s hPanel, Webmin, VestaCP, or CyberPanel etc.
OS with Panel:
- Perfect for the rapid deployment of targeted applications or software stacks.
- Pre-configured web servers, such as the MERN stack, content management systems (e.g., WordPress), or technology stacks like LAMP and LEMP.
OS with Applications:
In this blog, I will discuss an OS with Application that are easy to deploy, requiring no installation or setup of applications such as Node.js, MongoDB, Nginx, PM2, etc.
OS with Application
- Click on "Application" and select the MERN stack ( MongoDB, Express, Reactjs and Nodejs). Built on the Ubuntu 20.04 operating system. or latest.
Install addition feature for VPS
- It is your choice whether to install the malware scanner or not. If you do not want to install it, then checked the box or proceed with the default option.
Create Root Password
- Create a root password. This password is used to log in to your server. Make sure to keep it secure and confidential.
Finish your Server Setup
- Here you can see the summary of your server. Click on "Finish Setup" to complete the process. it will take a few minutes to set up your server just wait for a while.
- After the setup is complete, you will receive an email containing your server details. Please be aware that setting up your server may take some time. You will then be redirected to the Hostinger VPS panel page.
Onboarding Screen
Connect to VPS Server
- There are two ways to connect to a VPS server. You can use the online browser terminal provided by Hostinger, or you can use the terminal on your PC or laptop. If you choose to use the Hostinger terminal, you will find it at the top right side of the screen, as shown in the image.
If you want to use your pc or Laptop terminal then to on "SSH Access" and copy the ssh root@<ip_address> .
Open the terminal on your PC or laptop, paste the ssh root@<ip_address> , and then press Enter.
Press Enter. (enter yes)
Enter you root password.
Install Package
- In this setup, While installed the OS , I have selected "OS with applications" which including Node.js, Git, Nginx, PM2, MongoDB etc. To check if all these technologies are installed, use the following commands.
Clone Repository from Github
Two types of Repository are as follows :
- Public repositories are open and accessible to anyone on the internet.
- Go to Github account.
- Select the repo. Click on Code . Go to HTTPS section copy the url
- Go To terminal clone git using following command.
- Private repositories are accessible only to you, those you share access with, and certain members of your organization.
- Here is how you can clone your private repositories using a GitHub token.
- Go to Github account. Go To Settings Developer Settings Personal access tokens Tokens (classic) Right side Click on "Generate new token" Select "Generate new token" Note <enter_name_of_token> Select Exipiration date Select Scopes (permission)
- Make sure to copy your personal access token now. You won’t be able to see it again!
- To clone the GitHub repository, you need to format the command as follows using your token:
- Example :
- After cloning the repository, you need to install the necessary packages.
Public Repo:
Private Repo:
Add credentials to the .env file
- To add credentials to the .env file, you must install the nano package. This tool allows you to edit text directly in the terminal. Before installing, first check if it is already installed on the server.
- If nano is not installed, you must first install it. In Ubuntu, it's necessary to update the system before installing any applications.
- Create .env file following command.

Folder, pm2 and Nginx setup Here are the most useful Ubuntu commands for daily use.
System Updates & Upgrades
- # Update package lists
- # Upgrade installed packages
- # Smart upgrade handling dependencies
- # Remove unused packages
- # Update package lists
File & Directory Management
- # List files with details
- # Change directory
- # Show current directory
- # Create a new directory
- # Delete folder & contents (use with caution)
- # Copy directory recursively
- # Rename or move files/folders
- # Search for files
- # List files with details
Folder, pm2 and run on IP
- Go to root folder, check the list of folder by
- By default, the application folder is present. Navigate into this folder using the cd command.
- Use the git clone command to clone the repository, and include the token since I was using a private repository.
After the cloning process is complete, navigate to the folder and install the package.
After installing the package, set the credentials in the .env file.
We have now added the credentials to the .env file. Now, let's build this project using the command "npm run build."
Now that the build is completed, let's run the project using pm2 and check it in the browser. To run the project, we need to use the following command.
- Example :
- Now open you browser. <ip_address>:port.
- Exaple : 46.12.52.90:3000
- Your project running in ip with port.
Setup Domain and Run with Nginx.
- Go to your domain provider and add the IP of you VPS Hosting. For Example, I am using godaddy.com. Inside the domain settings, I set up the domain.
- I have a domain that is already running: amitprajapati.co.in. I will create a new sub-domain with my VPS hosting IP address, which is as follows.
- You can use you domain also only you need to setup the ip in @ and ip are as follow
- Next, access your VPS server terminal to configure the domain using your IP address and set up the proxy.
- Go the path are as follow.
Create the file for your domain configuration. I will create the file test.amitprajapati.co.in.conf for my domain name using the nano command.( you can give any name which you wanted)
In side this file you can added the following configuration are as shown in image.
- Press CTRL + X yes Enter
- Now you need to create the symbolic link in the site-enabled folder in the nginx folder. you need to go to the /etc/nginx/sites-enabled
- You can open the file using the following cmd.
- Press CTRL + X to Close
- Now you need to restart you nginx.
- Now you can open you browser. open the domain check the website is running if no error is there.
Install SSL on a VPS Using Certbot
Once it's ready, run the following to set up a Python virtual environment
Next, create a symbolic link so that Certbot can be executed from any path:
Since the SSL is active for 90 days, it is recommended to set up automatic renewal. You can do so by running the following:
