At first make a folder i.e "test" in server as path /var/www/html/test . Put a file as index.php or index.html in "test" folder and make file permission by bellows commands-

sudo chown <OS Username>  /var/www/html/test -R
sudo chmod 755 /var/www -R



Apache Virtual Hosts Settings;
At present-

Your present url: http://localhost/test
File path: /var/www/html/test
Desired url: test.dev

Step-1: Terminal command

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.dev.conf

Step-2: Past bellows code in /etc/apache2/sites-available/test.dev.conf

<VirtualHost *:80>
    ServerAdmin admin@test.dev
    ServerName test.dev
    ServerAlias www.test.dev
    DocumentRoot /var/www/html/test
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


Step-3: Optional Terminal command if you use a2ensite plugins

sudo a2ensite test.dev.conf
sudo gedit /etc/hosts

Step-4: Write in hosts file like bellow

127.0.0.1   localhost

#Virtual Hosts
127.0.0.1   test.dev

Step-5: Terminal command

sudo service apache2 restart

Step-6: Browse url test.dev


Nginx Virtual Hosts Settings 
General information

File path: /var/www/html/test
Desired url: test.dev

Step-1: Terminal command

sudo chown -R www-data:www-data /var/www/example.com/public_html
sudo chmod 755 /var/www

Step-2: Terminal command

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/test.dev

Step-3: Past bellows code in test.dev

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www/html/test;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name test.dev;
}

Step-4: Optional case as like in apache2 step-3
Sometime it make confused in domain name. To both avoid the "conflicting server name error" and ensure that going to your site displays the correct information, you can delete the default nginx server block:

sudo ln -s /etc/nginx/sites-available/test.dev /etc/nginx/sites-enabled/test.dev

sudo rm /etc/nginx/sites-enabled/default

Step-5: Terminal command

sudo gedit /etc/hosts

Step-6: Write in hosts file like bellow

127.0.0.1   localhost

#Virtual Hosts
127.0.0.1   test.dev

Step-7: Terminal command

sudo service nginx restart

Step-8: Browse url test.dev