2

I need make variable VirtualHost without reload Apache configuration when added domain. Does Apache have a variable %{???} that contains only the domain name? Variable %{???} must contain only the domain name "example.com" or "example.co.uk", but not subdomain "www.example.com" or "test.example.co.uk" as variable %{HTTP_HOST}

Variable VirtualHost:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        <If "-f '/var/certificates/%{???}/cert.pem'">
            ServerName %{???}
            ServerAlias *.%{???}
            SSLCertificateFile /var/certificates/%{???}/cert.pem
            SSLCertificateKeyFile /var/certificates/%{???}/private.pem
            SSLCertificateChainFile /var/certificates/%{???}/chain.pem
            #... other stuff ...
        </If>
    </VirtualHost>
</IfModule>

EDIT: I try use UseCanonicalName off whit variable %-2.0.%-1.0 for get two last part from host (domain name and TLD)

Variable %-2.0.%-1.0 for domain whit normal TLD (.com, .net, ...) is OK, but for TLD ".co.uk" is WRONG. No matter, I do not need TLD "co.uk".

"example.com" => "example.com" OK
"test.example.com" => "example.com" OK
"example.co.uk" => "co.uk" WRONG
"www.example.co.uk" => "co.uk" WRONG

But Apache after restart/reload whit new configuration not start when i use rows whit <If .... Error is "ServerName not allowed here". How else can I verify the existence of certificates?

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        UseCanonicalName Off
#       <If "-f '/var/certificates/%-2.0.%-1.0/cert.pem'">
            ServerName %-2.0.%-1.0
            ServerAlias *.%-2.0.%-1.0
            SSLCertificateFile /var/certificates/%-2.0.%-1.0/cert.pem
            SSLCertificateKeyFile /var/certificates/%-2.0.%-1.0/private.pem
            SSLCertificateChainFile /var/certificates/%-2.0.%-1.0/chain.pem
            #... other stuff ...
#       </If>
    </VirtualHost>
</IfModule>
Liubarskis
  • 21
  • 3
  • You're probably looking at https://httpd.apache.org/docs/2.4/mod/mod_vhost_alias.html but I don't think it will work with `SSLCertificateFile` and the like directives – Capsule Jun 28 '17 at 23:36
  • 1
    See https://stackoverflow.com/questions/41635535/non-wildcard-certificates-with-dynamic-apache-vhosts – Capsule Jun 28 '17 at 23:38

0 Answers0