I setup a subdomain in my sites-available folder, enabled it and done everything needed so that it restarts apache2 with no errors (changing default:443 to *:443, adding NameVirtualHost *:443 to ports.conf, etc).

The subdomain now works perfectly but when I try to access any page using SSL on the main domain it jumps to my error page. It seems to have taken over all SSL.

Ex: subdomain.domain.com

Apache2 error: File does not exist: /var/www/subdomain/foldername

It should not be reading from the subdomain folder for this. My guess is it is a problem in my virtual host setup below:

    <VirtualHost *:443>
    ServerName subdomain.domain.com
    ServerAlias subdomain.domain.com
    VirtualDocumentRoot /var/www/subdomain/
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/domain.com.crt
    SSLCertificateKeyFile /etc/apache2/ssl/domain.com.key
    SSLCertificateChainFile /etc/apache2/ssl/domain.com.crt
    SSLCACertificateFile /etc/apache2/ssl/bundle.crt
    SSLProtocol all
    SSLCipherSuite HIGH:MEDIUM

Results of apachectl -S:

    VirtualHost configuration:
    wildcard NameVirtualHosts and _default_ servers:
    *:443    is a NameVirtualHost
             default server subdomain.domain.com (/etc/apache2/sites-enabled/subdomain.domain.com:1)
             port 443 namevhost subdomain.domain.com (/etc/apache2/sites-enabled/subdomain.domain.com:1)
             port 443 namevhost *.domain.com (/etc/apache2/sites-enabled/default-ssl:2)
    *:80     is a NameVirtualHost
             default server production1 (/etc/apache2/sites-enabled/000-default:1)
             port 80 namevhost production1 (/etc/apache2/sites-enabled/000-default:1)
    Syntax OK
  • Can you provide the output from apachectl -S? – Shane Madden Jul 15 '13 at 5:47
  • Added to question. – codephobia Jul 15 '13 at 5:54

SSL virtual host configurations are just like normal ones; they don't inherit directives from the corresponding non-SSL vhost configurations or anything.

Since you have specified the directive VirtualDocumentRoot /var/www/subdomain/, apache will use this folder for all the requests which match this vhost (eg. for subdomain.domain.com). You should change this to the actual location you'd like it to use for the webroot.

Also, one point: you don't need to specify a name in ServerAlias if it's the ServerName.

That you are using wildcard SSL isn't particularly relevant to this problem.

Also, ensure that each site you have has its own SSL virtualhost configuration parallel with the cleartext one. Be aware that the default vhost for port 443 (the first one on the search path in alphabetical order) will be used if the client doesn't support SNI but is using SSL.

Looking at your apachectl -S output, you will need to do a few things:

  • Rename your default SSL vhost config file so that it is alphabetically before all others
  • Remove the wildcard ServerName or ServerAlias from the default SSL vhost and replace it with domain.com (and www.domain.com if you like). It will match all unmatched subdomains by virtue of being the default; the wildcard will make it match everything so that subdomain.domain.com matches the default vhost too.
  • Yes but it is also using it for a URL like domain.com/login as per my confusion and the error log. – codephobia Jul 15 '13 at 5:48
  • Yes, I was in the middle of typing that last bit out. – Falcon Momot Jul 15 '13 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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