1

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?

2 Answers 2

1

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.

1
  • 1
    I would imagine the initial VirtualHost configuration in the default file would be what is causing the override. May 26, 2011 at 14:38
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .