CodexBloom - Programming Q&A Platform

Apache 2.4.54 - Configuring Virtual Hosts with Different SSL Certificates per Subdomain

๐Ÿ‘€ Views: 32 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-14
apache ssl virtualhost

Can someone help me understand I am trying to set up multiple SSL virtual hosts in Apache 2.4.54 on my Ubuntu 22.04 server, with each subdomain using its own SSL certificate. I have the certificates and keys for each subdomain correctly placed in `/etc/ssl/certs/` and `/etc/ssl/private/`, but when I try to access them, I get a `SSL_ERROR_BAD_CERT_DOMAIN` behavior in the browser. Hereโ€™s my current `000-default.conf` configuration: ```apache <VirtualHost *:80> ServerName example.com Redirect permanent / https://example.com/ </VirtualHost> <VirtualHost *:443> ServerName example.com DocumentRoot /var/www/example SSLEngine on SSLCertificateFile /etc/ssl/certs/example.com.crt SSLCertificateKeyFile /etc/ssl/private/example.com.key </VirtualHost> <VirtualHost *:443> ServerName sub.example.com DocumentRoot /var/www/sub SSLEngine on SSLCertificateFile /etc/ssl/certs/sub.example.com.crt SSLCertificateKeyFile /etc/ssl/private/sub.example.com.key </VirtualHost> ``` I also have the necessary modules enabled: ```bash sudo a2enmod ssl sudo a2ensite default-ssl ``` After reloading Apache with `sudo systemctl reload apache2`, the main domain works fine with HTTPS, but the subdomain still fails with the SSL behavior. Iโ€™ve verified that both certificates are valid and not expired, and the DNS records for the subdomain are correctly pointed to my serverโ€™s IP address. Is there something I might be missing in my configuration or setup that could cause this behavior? Any help would be greatly appreciated! This is my first time working with Apache 3.11. Am I missing something obvious?