# Configuring Multiple Websites in Nginx Web Server

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.

**<mark>Step 1 : Install Nginx</mark>**

Update system's package

```plaintext
sudo apt update
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723022553975/1aee3eff-cda9-4e26-8f32-d6d41fcbe7b3.png align="center")

Install nginx package

```plaintext
sudo apt-get install nginx
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723022591145/7364a3eb-3bd2-4d5c-85ec-39554fbaa60f.png align="center")

Start & Restart the nginx service

```plaintext
sudo service nginx start
sudo service nginx restart
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723025468536/2f988653-d8a3-42fc-a928-376e00201b63.png align="center")

Check the nginx status

```plaintext
 sudo service nginx status
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723022660453/562f3f9e-0d34-4e5d-937e-2bbcf63f2266.png align="center")

Enable the nginx service

```plaintext
sudo systemctl enable nginx
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723025522992/b9643279-17a8-41c4-905d-75e2dce77974.png align="center")

**<mark>2.Configure Nginx</mark>**

Create folder for website 1 & 2

```plaintext
sudo mkdir -p /var/www/html/web1
sudo mkdir -p /var/www/html/web2
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723022890748/70e029d2-eb83-4a98-838d-289324354383.png align="center")

change the ownership for that two sites folders.

```plaintext
sudo chown -R $USER:$USER /var/www/html/web1
sudo chown -R $USER:$USER /var/www/html/web2
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723022916887/111eb819-d68e-40db-8817-776089f8e2bb.png align="center")

Create the index html file in webserver 1 & 2

```plaintext
vi /var/www/html/web1/index.html
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723023086931/7922d765-3527-4c99-a7bb-db1a0b94d335.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723023245202/6b306aaf-e0dd-4459-9373-69eb890109d0.png align="center")

Create the site configuration file for site 1 & 2 in sites-availabe folder and add the below content on it.

```plaintext
sudo vi /etc/nginx/sites-available/web1.conf
```

```plaintext
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;
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723023807831/10c1396b-892b-4fa9-9cc1-7e80e7c31c9e.png align="center")

```plaintext
sudo vi /etc/nginx/sites-available/web2.conf
```

```plaintext
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;
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024040355/c13937c7-67dc-46dc-ba64-b593a1d9db4b.png align="center")

Enable the websites 1 & 2 which is we want to publish to public.

```plaintext
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/
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024133330/ca885442-0c67-412d-a95d-9e021cdab2fd.png align="center")

Modify the default web root permission.

```plaintext
sudo chmod -R 755 /var/www/html/
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024185558/c93c5410-800c-44e8-a2ae-b423683a63e9.png align="center")

Verify our configuration made on nginx is corrcet.

```plaintext
sudo nginx -t
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024214235/df0a0716-e4ca-449e-9b60-08a152db85ae.png align="center")

Restart the nginx service

```plaintext
sudo service nginx restart
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024250559/e377d149-f3f3-40fb-85f3-f78beb7572e1.png align="center")

Check the nginx status

```plaintext
sudo service nginx status
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024287504/a35dad75-b57b-4233-9798-3cb328e400a6.png align="center")

**<mark>Step 3 : Create A record for both sites :</mark>**

I have domain in GoDaddy. Need to login GoDaddy account.

`Create A record for site 1`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024414999/a89ad9b2-7938-4f1a-8bfc-32b8c4a44d5a.png align="center")

`Create A record for site 2`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024490764/bed69f84-f7b8-426a-aeca-57523f9b1bcb.png align="center")

Now, check the sites are working or not

**<mark>Site 1</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024829041/cc3196e7-ca16-451d-9bf2-db1a367e05e8.png align="center")

**<mark>Site 2</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1723024860024/0b250dc4-7fac-4def-9fa6-11318e1f54ee.png align="center")

Now, successfully configured multisite in Nginx web server.
