Wednesday, 17 January 2018

thumbnail

How to configure virtualhost in Nginx on Ubuntu-16.04

Introduction


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 
http://www.techs2resolve.in/2018/01/how-to-install-and-configure-lemp-in.html

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 :- test.techs2resolve.in. 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:- 
192.168.1.10     test.techs2resolve.in

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

sudo cp -av /etc/nginx/sites-available/default /etc/nginx/sites-available/test.techs2resolve.in


2. Now edit your conf file  like below :-

sudo vim /etc/nginx/sites-available/test.techs2resolve.in

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/test.techs2resolve.in

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

sudo vim /var/www/html/test.techs2resolve.in/index.php

Enter the below code in file :-

<?php 
phpinfo();
?>


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

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

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