Configuring Multiple Websites in Nginx Web Server

Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
Search for a command to run...

Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
No comments yet. Be the first to comment.
1. Difference between Docker and Kubernetes Docker → Builds and runs containers.Kubernetes → Orchestrates containers across multiple nodes. Key points: Docker = container runtime. Kubernetes = container orchestration tool. Kubernetes provides auto...
In this session, we learn how to monitor a Kubernetes cluster using Prometheus and Grafana.This is not just theory — there is a GitHub repository containing all installation commands and demo steps.The repo will also be enhanced later with advanced K...
1. What is a ConfigMap in Kubernetes? A ConfigMap is used to store non-sensitive configuration data that your application needs — such as: Database port Connection type Any general configuration values In normal applications (non-Kubernetes), de...
Kubernetes normally supports built-in resources like: Deployment Service Pod ConfigMap Secret Ingress These are called native resources. Sometimes companies (Istio, ArgoCD, Prometheus Operator, Kyverno, etc.) want to add new features that Kub...
1. Why Kubernetes Services Are Needed When a Pod is created in Kubernetes, it receives a dynamic IP address.If the Pod dies and restarts, its IP changes.So other Pods (like checkout → payments) cannot rely on Pod IP because it changes, creating issue...
NGINX is open-source web server software used for reverse proxy, load balancing, and caching. It provides HTTPS server capabilities and is mainly designed for maximum performance and stability. It also functions as a proxy server for email communications protocols, such as IMAP, POP3, and SMTP.
Step 1 : Install Nginx
Update system's package
sudo apt update

Install nginx package
sudo apt-get install nginx

Start & Restart the nginx service
sudo service nginx start
sudo service nginx restart

Check the nginx status
sudo service nginx status

Enable the nginx service
sudo systemctl enable nginx

2.Configure Nginx
Create folder for website 1 & 2
sudo mkdir -p /var/www/html/web1
sudo mkdir -p /var/www/html/web2

change the ownership for that two sites folders.
sudo chown -R $USER:$USER /var/www/html/web1
sudo chown -R $USER:$USER /var/www/html/web2

Create the index html file in webserver 1 & 2
vi /var/www/html/web1/index.html

vi /var/www/html/web2/index.html

Create the site configuration file for site 1 & 2 in sites-availabe folder and add the below content on it.
sudo vi /etc/nginx/sites-available/web1.conf
server
{
listen 80;
listen [::]:80;
root /var/www/html/web1;
index index.html index.htm index.nginx-debian.html index.php login.html;
server_name site1.dineshcloud.in www.site1.dineshcloud.in;
}

sudo vi /etc/nginx/sites-available/web2.conf
server
{
listen 80;
listen [::]:80;
root /var/www/html/web2;
index index.html index.htm index.nginx-debian.html index.php login.html;
server_name site2.dineshcloud.in www.site2.dineshcloud.in;
}

Enable the websites 1 & 2 which is we want to publish to public.
sudo ln -s /etc/nginx/sites-available/web1.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/web2.conf /etc/nginx/sites-enabled/

Modify the default web root permission.
sudo chmod -R 755 /var/www/html/

Verify our configuration made on nginx is corrcet.
sudo nginx -t

Restart the nginx service
sudo service nginx restart

Check the nginx status
sudo service nginx status

Step 3 : Create A record for both sites :
I have domain in GoDaddy. Need to login GoDaddy account.
Create A record for site 1

Create A record for site 2

Now, check the sites are working or not
Site 1

Site 2

Now, successfully configured multisite in Nginx web server.