Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

There's another VirtualHost block for port 443 somewhere, either loading before your intended ones or bound to a specific address instead of *, which is getting the requests to that location; that's the only way that content would get served.

Beyond that, for the config that you are aiming for, you also need to make sure that you have a NameVirtualHost *:443 directive alongside the existing NameVirtualHost *:80; depends on your config layout, but usually in ports.conf.

share|improve this answer
1  
I would imagine the initial VirtualHost configuration in the default file would be what is causing the override. –  KayakJim May 26 '11 at 14:38
add comment

Problem has been solved.

I followed the advice about another VirtualHost that is blocking my own configuration and found it. It was and:

<VirtualHost _default_:443>

defined in ssl.conf. The thing is that the file was in conf.d/ (running on Fedora) directory so I didn't notieced it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.