adding subdomain in apache virtual host

Posted January 13, 2019 32k views
UbuntuApacheDigitalOceanNetworkingUbuntu 18.04

I am trying to configure a subdomain: ( is replaced by my actual domain name)

I already had virtual hosts set up with 2 sites: and they both had separate directories and where working correctly as separate sites.

Now I want to add also with its own separate documentroot. I added a config file called: “” with this inside:

<VirtualHost *:80>
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

I added the folder /var/www/ with an example index.html inside. I gave the folder the right permissions. After that I enabled the site with: “a2ensite” and restarted apache.

I added a new record to the records. It is an A record with and it redirects to the same ip as because they are on the same server.

After doing all of this I expected that when I went to that it would show me the example index.html that I had created but it did not. When I go to it is the same thing as if I would go to

What am I doing wrong?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


You are redirecting the traffic from to so you need to setup another virtual host for where it listen on port 443 and uses a certificate for

Because you do not currently have this config file, it shows the default site

Hope this helps