I have two VirtualHost on one Apache, one 000-default.conf and one site.conf. SSL is enabled on site.conf and a certificate is attached. If you access the browser from https://site.com , then the host site.com opens, if via http, then similarly, there is a redirect to https. If you access http: // ip , then 000-default opens, but if you use https: // ip , site.com opens with a warning about an insecure connection, since the certificate is bound to IP. How to make the 000-default open when accessing https: // ip or redirect to http?
Configs:
000-default:
<VirtualHost ip.ip.ip.ip:80> ServerName ip.ip.ip.ip ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> site.com:
<VirtualHost site.com:443> ServerName site.com ServerAdmin webmaster@localhost DocumentRoot /home/site/www SSLEngine on SSLProtocol all -SSLv2 SSLCertificateFile /path/to/ssl_certs/cert.crt SSLCertificateKeyFile /path/to/ssl_certs/key.key SSLCertificateChainFile /path/to/ssl_certs/chainfile.crt ErrorLog /home/site/error.log CustomLog /home/site/access.log combined <Directory /home/site/www> AllowOverride All Require all granted </Directory> <IfModule mpm_itk_module> AssignUserId user group </IfModule> </VirtualHost> <VirtualHost site.com:80> ServerName site.com RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </VirtualHost>