This is an extension (not a dupe) of How to disable non-ssl connection on Apache 2.2
Like the above question, I have:
Added a virtual host config /etc/apache2/sites-available/example.com.conf with an SSL cert.
<IfModule mod_ssl.c>
<VirtualHost example.com:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /my/certs/mydomain.com.cert
SSLCertificateKeyFile /my/certs/mydomain.com.key
SSLCACertificateFile /my/certs/myprovider.ca
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
Then:
- Run
a2enconf ssl
to enable SSL. - Run
a2ensite example.com
to enable my domain. - Run
a2dissite 000-default
to disable the host default site. - Run
a2dissite default-ssl
to disable the host default ssl site.
What should remain is only the site https://example.com/
However, I can also access http://example.com/ (non-SSL) which is an unexpected feature.
The other question's answers are to simply disable port 80 by commenting out Listen 80
but that means that other virtual hosts won't be able to specify port 80.
Why does Apache2 appear to accept port 80 when no virtual host specifies it and what is the correct way without disabling port 80 altogether?