Create a virtual host on the Nginx server

Author: Al-mamun Sarkar Date: 2020-04-14 07:48:56

Create a virtual host on the Nginx server. The following commands show how to create a virtual host on the Nginx server. 

 

Unlink default configuration file:

unlink /etc/nginx/sites-enabled/default

We will create a custom configuration file.

Check sites-available if the default is there remove that also.

unlink /etc/nginx/sites-available/default

 

Go to Nginx conf.d directory:

cd /etc/nginx/conf.d/

 

Create a configuration file:

touch artofcse.local.conf

 

Edit the configuration file:

vim artofcse.local.conf

Add the following code there

server {
        listen 80;
        root /var/www/artofcse.com;
}

 

Create artofcse.com directory:

mkdir /var/www/artofcse.com

 

Create index.html file inside artofcse.com directory:

echo "Site coming soon" > /var/www/artofcse.com/index.html

 

Test Nginx configurations:

nginx -t

 

If it's ok then restart Nginx:

systemctl reload nginx

 

Browse by your computer IP address or http://127.0.0.1 for the local computer. You will see the Site coming soon.