0

My apache is configured to use multiple VirtualHosts:

  • default-ssl.conf for mydomain.tld and www.mydomain.tld and
  • subdomain-le-ssl.conf for subdomain.mydomain.tld

default-ssl.conf:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
            ServerAdmin my@mail
            ServerName mydomain.tld
            ServerAlias www.mydomain.tld
            DocumentRoot /var/www/html

            <Directory /var/www/html>
              # directory stuff
            </Directory>

            # ssl stuff
    </VirtualHost>
</IfModule>

Problem

If someone has a typo in subdomain (i.e. curl https://subdonain.mydomain.tld), he gets a 503 Service Unavailable which is confusing. I would like to serve the default-ssl.conf VirtualHost in this case.

In my VirtualHost config for *:80 i removed ServerName and ServerAlias to address this issue, and it works as intended. But when i do the same in default-ssl.conf i get error 503 for every https request.

How do i configure my *:443 Hosts to behave like the *:80 Hosts in that regard?

Second Thoughts

Accessing mydomain.tld with an unknown subdomain will result in HTTPS cert errors. But i like an cert error better than Service Unavailable.

In my environment i have to fall back to doing my http(s) requests via IP occansionally because there is no domain available. But this requires the server to respond even if the ServerAlias is not set, which does not work. Editing /etc/hosts on clients is not an option, because those may be iphones/windows pcs and most certainly not developers.

I could fall back to using http on *:80 again, but i don't want that, because it would mean disabling the rewrite rule to https - which is bad practice.

I tried setting the ServerAlias * in default-ssl.conf which redirects everything to default-ssl.conf, but this means i can't access subdomain.mydomain.tld anymore.

HomelessGamer
  • 421
  • 4
  • 3
  • Your last trick serverAlias * will work. Give different filename start from alphabet A to C for subdomain-le-ssl.conf . eg.abcsubdomain-le-ssl.conf . – Sunil Bhoi Sep 05 '18 at 10:34
  • `$ ls 999-default-ssl.conf 010-subdomain-le-ssl.conf` This actually works. Even though it looks pretty dirty and very different from my non-ssl configs... – HomelessGamer Sep 05 '18 at 10:55

0 Answers0