Adding Multiple Domains to Apache

1 — Create the Directory Structure

sudo mkdir -p /var/www/

2 — Grant Permissions

sudo chown -R www-data:www-data  /var/www/

3 — Create New Virtual Host Files

sudo nano /etc/apache2/sites-available/

The file should contain the following

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/>
    AllowOverride All

Enable Rewrite

sudo a2enmod rewrite

4 — Enable the New Virtual Host Files

sudo a2ensite

Disable the Default

sudo a2dissite 000-default.conf

5 – Restart Apache

sudo systemctl restart apache2

6. — Set Up Local Hosts File (Optional)

Open up the host file on the system

sudo nano /etc/hosts

In the file, fill up accordingly   localhost   guest-desktop

7. Setup SSL – Lets Encrypt

This assumes Certbot has aleady been setup. If not, please go to “Setup of Certbot”

sudo certbot --apache

Verify Certbot Renewal

sudo systemctl status certbot.timer
sudo certbot renew --dry-run
Scroll to Top