Step 2: Add your Virtual host configuration files.
Next we add the Virtual host files which will have the Virtual host infomation for the projects.
sudo cp /usr/nginx/conf.d/default.conf /usr/nginx/conf.d/site1.local.conf
sudo cp /usr/nginx/conf.d/default.conf /usr/nginx/conf.d/site2.local.conf
Step 3: Setup your Virtual Host
Open your Virtual host file for Site 1 and configure it.
sudo vim site1.local.conf
We need to make a couple of changes in this file.
Similarly, setup the Virtual host for Site 2.
The index section tell what is the type of the files that is allowed as the project’s index files. For PHP it will be index index.php
Step 4: Restart the Nginx server
You will need to restart the Nginx server to have the changes in effect.
sudo services nginx restart
Step 5: Add in the site entries in hosts file.
For localhosts you will have to add the server_name in the hosts file to access.
sudo vim /etc/hosts
You can add the local hosts details to this file. As long as that line is there, directing your browser toward, say, example.com will give you all the virtual host details for the corresponding IP address.
The last block can be used when you are woking on a VM or a Vagrant box. So, you can add the ip of the VM along with the host name to point your browser to the desired location and access with the Virtual Host.
Step 6: Access you projects with the Virtual Hosts in the browser.
Now, when you type in http://site1.local it should show up like this.
For Site Two, enter http://site2.local.
To add more virtual hosts, you can just repeat the process above, being careful to set up a new document root with the appropriate domain name, and then creating and activating the new virtual host file.