My first VirtualHost had the ServerName "example.com" and the ServerAlias "www.example.com".
My second VirtualHost had the ServerName "sub1.example.com".
After changing the first VirtualHost from the ServerAlias "www.example.com" to " *.example.com "
the DocumentRoot of the first VirtualHost is always loaded ignoring which SubDomain is called.
I need the wildcard definition in the Alias for my SSL cert...
E.g. I type sub1.example.com into the address bar of my browser and instead of loading the contents
from "/var/www/sub1.example.com" I always get the content from "/var/www/example.com".
How can I solve this issue to use a wildcard in the ServerAlias and use additional specified subdomains?
This is my first VirtualHost:
- Code: Select all
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/custom-ca.crt
SSLCertificateKeyFile /etc/ssl/custom-ca.key
</VirtualHost>
This is my second VirtualHost:
- Code: Select all
<VirtualHost *:80>
ServerName sub1.example.com
RedirectPermanent / https://sub1.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName sub1.example.com
DocumentRoot /var/www/sub1.example.com
<Directory /var/www/sub1.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/custom-ca.crt
SSLCertificateKeyFile /etc/ssl/custom-ca.key
</VirtualHost>