I want to redirect HTTPS connections to my domain towards a unique subdomain using Apache2 reverse proxy. I want all the connections that come to a.example.com to be redirected towards $random$.b.example.com. To generate the random value I have a script running on port 3000, all requests for a.example.com are proxied to my script which sends back a reply to client with the 302 redirect code and the new domain $random$.b.example.com and then all connections towards $random$.b.example.com are supposed to be served normally.
I have key and certificates for a.example.com and $random$.b.example.com (wildcard certificate *.b.example.com). However when my client receives the redirect it throws invalid peer certificate: CertNotValidForName and does not move on to query $random$.b.example.com. What am I doing wrong?
My virtual hosts look like this:
IfModule mod_ssl.c> <VirtualHost *:443> ServerName a.example.com SSLProxyEngine on ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined SSLEngine on SSLCertificateFile /etc/apache2/ssl/wildcard_domain.pem SSLCertificateKeyFile /etc/apache2/ssl/wildcard_domain.key </VirtualHost> <VirtualHost *:443> ServerAdmin webmaster@localhost ServerName b.example.com ServerAlias *.b.example.com DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined SSLEngine on SSLCertificateFile /etc/apache2/ssl/wildcard_domain.pem SSLCertificateKeyFile /etc/apache2/ssl/wildcard_domain.key <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> Alias /data /path/to/data <Directory /path/to/data> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> </IfModule>