Sunday 9 December 2018

Virtual Host

Guide to make Virtual Hosts In Apache2
Create Virtual Hosts Config Files

# sudo vim /etc/apache2/sites-available/VirtualHost1.conf
# sudo vim /etc/apache2/sites-available/VirtualHost2.conf
# sudo vim /etc/apache2/sites-available/VirtualHost3.conf

Config Each Virtual Host file

// Virtual Host 1 sample file 
// Domain should be registered or purchased. Else need to update /etc/hosts file in local machine to map the whateverdomain.com to the server IP

    ServerName www.virtualhost1.com
    ServerAdmin webmaster@virtualhost1.com
    DocumentRoot /var/www/html/virtualhost1.com
    ErrorLog /var/log/apache2/virtual.host.error.log
    CustomLog /var/log/apache2/virtual.host.access.log combined
    LogLevel warn


// Do the same thing for other host file

Create Document Root Directories for the virtual hosts

# sudo mkdir -p /var/www/html/virtualhost1.com
# sudo mkdir -p /var/www/html/virtualhost2.com
# sudo mkdir -p /var/www/html/virtualhost3.com

Enable Each Site

# sudo a2ensite VirtualHost1.conf
# sudo a2ensite VirtualHost2.conf
# sudo a2ensite VirtualHost3.conf

Restart Apache2

# sudo systemctl restart apache2

Source

No comments:

Post a Comment