Wednesday, 17 January 2018


How to configure virtualhost in Nginx on Ubuntu-16.04


In this tutorial we are going to see  how to configure virtualhost in Nginx on Ubuntu-16.04 server. For the demo purpose I have taken AWS-EC2 instance. I have successfully installed LEMP server.

To install LEMP server you can click on below link

After you have installed LEMP follow the below step to configure.

Note:- Please make sure that you replace the domain name with your own like my :- Also create A record in Domain DNS which points to your servers Public IP.

For testing purpose you can add host entry in your local systems host file  /etc/hosts like below:-

1. Copy the default configuration file with your domain name :-

sudo cp -av /etc/nginx/sites-available/default /etc/nginx/sites-available/

2. Now edit your conf file  like below :-

sudo vim /etc/nginx/sites-available/

3. You have to make 3 changes in conf file like below :-

1.  Remove default_server parameter from line no 17
2.  Change the Document Root path with your folder on line no 36
3.  Change the server_name with your domain name on line 41

The file will look like below :-

4.  Create the directory for your data to be stored :-

sudo mkdir /var/www/html/

5. Create a index.php file inside your Document Root Directory :-

sudo vim /var/www/html/

Enter the below code in file :-


6. Now enable the site so that we can check :-

cd /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/ .

7. Now test in browser :-

That's it
Please do Comments, Likes and Share

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

Follow by Email