How To Set Up Apache Virtual Host with Subdomain - Digitalocean
Set Up Apache Virtual Host with Subdomain - Digitalocean
Configure Apache HTTP Server with Domain Name - Digitalocean
First you will need check this article :
How to Add a Subdomain to Your Domain
Create the Virtual Host File
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-blog.conf
Open the new file in your editor with root privileges
sudo nano /etc/apache2/sites-available/000-blog.conf
Change ServerName and ServerAlias
ServerName blog.barrouh.com
ServerAlias www.blog.barrouh.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.blog.barrouh.com [OR]
RewriteCond %{SERVER_NAME} =blog.barrouh.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Create the Virtual Host File for SSL
sudo cp /etc/apache2/sites-available/000-default-le-ssl.conf /etc/apache2/sites-available/000-blog-le-ssl.conf
Open the new file in your editor with root privileges
sudo nano /etc/apache2/sites-available/000-blog-le-ssl.conf
Change ServerName and ServerAlias
ServerName blog.barrouh.com
ServerAlias www.blog.barrouh.com
Enable the New Virtual Host Files
sudo a2ensite 000-blog.conf
sudo a2ensite 000-blog-le-ssl.conf
Restart Apache to make these changes take effect
sudo systemctl restart apache2