Assuming the certificates are correct, there certainly is a detail in your configuration that explains this behaviour. From Apache Virtual Host Matching, the emphasis is mine:
If the connection is using SSL, the server supports Server Name Indication, and the SSL client handshake includes the TLS extension with the requested hostname, then that hostname is used below just like the Host: header would be used on a non-SSL connection. Otherwise, the first name-based vhost whose [IP] address matched is used for SSL connections. This is significant because the vhost determines which certificate the server will use for the connection.
Your <VirtualHost *:443>
blocks are missing ServerAlias
directives for the www
subdomains. Therefore, the first VirtualHost
is used as a default name based virtual host, instead.
Furthermore, the ServerName
could be used without the optional [:port]
as there is no need to distinguish the virtual hosts by ports.
Also notice that SSLCACertificateFile
is for client authentication:
This directive sets the all-in-one file where you can assemble the Certificates of Certification Authorities (CA) whose clients you deal with. These are used for Client Authentication. Such a file is simply the concatenation of the various PEM-encoded Certificate files, in order of preference.
The filename example_com.ca-bundle
suggests you might have confused this with (deprecated) SSLCertificateChainFile
; since 2.4.8 the SSLCertificateFile
may also include intermediate CA certificates, sorted from leaf to root.
An example with a macro that can reduce the copy-paste configuration as well as handle the redirects from HTTP to HTTPS:
NameVirtualHost *:80
NameVirtualHost *:443
<Macro VHost $domain $tld>
<VirtualHost *:80>
ServerName $domain.$tld
ServerAlias www.$domain.$tld
Redirect permanent / https://$domain.$tld/
</VirtualHost>
<VirtualHost *:443>
ServerName $domain.$tld
ServerAlias www.$domain.$tld
DocumentRoot "/var/www/html"
ErrorLog logs/ssl_$domain_$tld_error_log
TransferLog logs/ssl_$domain_$tld_access_log
LogLevel warn
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/$domain_$tld.crt
SSLCertificateKeyFile /etc/pki/tls/private/$domain_$tld.key
</VirtualHost>
</Macro>
Use VHost example com
Use VHost example net
Use VHost example org