Ask anything about this post!
In this guide, we'll walk through the process of hosting multiple websites on an Ubuntu VPS using NGINX. By the end of this tutorial, you'll have several websites hosted on a single VPS with NGINX serving as the web server.
Syntax:
ssh -p PORT USERNAME@HOSTIP
Example:
ssh -p 22 abhi@203.32.44.92
First, ensure that your server has NGINX installed. Open a terminal and run the following commands:
sudo apt update && sudo apt upgrade
sudo apt install nginx
Verify NGINX is installed:
nginx -v
Check if NGINX is running:
sudo service nginx status
There are two ways to do it:
Syntax:
scp -P Remote_Server_Port Source_File_Path Destination_Path
Example:
scp -P 1034 codebhaiya.zip abhi@203.32.44.92
Syntax:
ssh -p PORT USERNAME@HOSTIP
Example:
ssh -p 22 abhi@203.32.44.92
Syntax:
unzip zip_file_name
Example:
unzip codebhaiya.zip
Syntax:
ssh-keygen -t ed25519 -C "your_email@example.com"
If Permission Denied then Own .ssh then try again to Generate SSH Keys
Syntax:
sudo chown -R user_name .ssh
Example:
sudo chown -R abhi .ssh
Open Public SSH Keys then copy the key
cat ~/.ssh/id_ed25519.pub
Syntax:
git clone ssh_repo_path
Example:
git clone git@github.com:abhinayjangde/codebhaiya.git
Create Virtual Host File
Syntax:
sudo nano /etc/nginx/sites-available/your_domain
Example:
sudo nano /etc/nginx/sites-available/codebhaiya.com
Write following Code in Virtual Host File
Syntax:
server{
listen 80;
listen [::]:80;
server_name your_domain www.your_domain;
root /var/www/project_folder_name;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Example:
server{
listen 80;
listen [::]:80;
server_name codebhaiya.com www.codebhaiya.com;
root /var/www/project_folder_name;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Enable Virtual Host or Create Symbolic Link of Virtual Host File
Syntax:
sudo ln -s /etc/nginx/sites-available/virtual_host_file /etc/nginx/sites-enabled/virtual_host_file
Example:
sudo ln -s /etc/nginx/sites-available/codebhaiya.com /etc/nginx/sites-enabled/codebhaiya.com
Check Configuration is Correct or Not
sudo nginx -t
By following these steps, you can host multiple websites on your Ubuntu VPS using NGINX. Each website has its own configuration, and you can easily add more by repeating the process. Happy hosting!
Thank you for reading our blog!
We have a Discord community where you can ask questions and get help from the community.
No comments yet. Be the first to share your thoughts!