I have an apache installation at mydomain.com
with document root at:
/var/www/html/
There are three folders in document root:
myapp1
myapp2
mysite
I want the following configuration with subdomains:
myapp1.mydomain.com --> /var/www/html/myapp1
myapp2.mydomain.com --> /var/www/html/myapp2
www.mydomain.com --> /var/www/html/mysite
mydomain.com --> /var/www/html/mysite
The configuration has to work for plain text HTTP and for HTTPS. I've used virtual hosts to achieve this. For example:
<VirtualHost *:80>
DocumentRoot /var/www/html/myapp1
ServerName myapp1.mydomain.com
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html/myapp1
ServerName myapp1.mydomain.com
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/server.key
SSLCertificateFile /etc/pki/tls/certs/server.crt
</VirtualHost>
Same configuration is for myapp2
and www.mydomain.com
. But I have a problem when I try to configure the SSL virtual host for the root domain: mydomain.com
. This is the config:
<VirtualHost *:443>
ServerName mydomain.com
DocumentRoot /var/www/html/mysite
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/server.key
SSLCertificateFile /etc/pki/tls/certs/server.crt
</VirtualHost>
This doesn't work. Going to https://mydomain.com
brings me to the default document root (/var/www/html
) and displays apache default welcome page. It seems that apache doesn't register this virtual host. It's interesting that a virtual host for plain HTTP mydomain.com
works i.e. going to http://mydomain.com
brings me to the /var/www/html/mysite
.
Why can't I have a SSL virtual host for root domain while every other virtual host works just fine?