The virtual hosting concept is used by companies to host multiple websites using a single machine. It can be achieved either by an ‘IP-based’ method or a ‘name-based’ approach. In ‘IP-based’ hosting we have distinct IP addresses for each website. In the case of ‘name-based’ hosting, we have multiple names running on each IP address.
In this Video, we will see how we can host two virtual hosts on an Ubuntu 20.04 - 22.04 system using name-based virtual hosting. We will use the Apache web server.
Useful Links:
VPS/VDS - https://www.mivocloud.com/
WARNING - ANGLED BRACKETS AREN'T ALLOWED IN DESCRIPTION SO BE ATTENTIVE TO THE VIDEO IN NANO REDACTOR
Commands Used:
sudo apt install apache2 -y
sudo systemctl restart apache2
sudo systemctl status apache2
sudo mkdir -p /var/www/host1/public_html
sudo mkdir -p /var/www/host2/public_html
sudo chown -R $USER:$USER /var/www/host1/public_html
sudo chown -R $USER:$USER /var/www/host2/public_html
sudo chmod -R 755 /var/www
sudo echo “Welcome to Virtual Host 1.” /var/www/host1/public_html/index.html
sudo echo “Welcome to Virtual Host 2.” /var/www/host2/public_html/index.html
sudo sh -c "echo 127.0.0.1 www.host1.com /etc/hosts"
sudo sh -c "echo 127.0.0.1 www.host2.com /etc/hosts"
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/host1.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/host2.conf
nano /etc/apache2/sites-available/host1.conf
VirtualHost *:80
ServerAdmin [email protected]
ServerName host1
ServerAlias www.host1.com
DocumentRoot /var/www/host1/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
/VirtualHost
nano /etc/apache2/sites-available/host2.conf
VirtualHost *:80
ServerAdmin [email protected]
ServerName host2
ServerAlias www.host2.com
DocumentRoot /var/www/host2/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
/VirtualHost
sudo a2ensite host1.conf
sudo a2ensite host2.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
curl www.host1.com
curl www.host2.com
Watch video How to Configure Apache Virtual Hosts on Ubuntu 20.04 - 22.04 online, duration hours minute second in high quality that is uploaded to the channel MivoCloud 21 July 2023. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 2,316 times and liked it 62 visitors.