: How can I force a VirtualHost in Apache to not listen for undefined subdomains on 443? In /etc/apache2/sites-available/example.com: <VirtualHost *:443> ServerName www.example.com
In /etc/apache2/sites-available/example.com:
<VirtualHost *:443>
ServerName example.com DocumentRoot /var/www/example.com/htdocs
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
I also have a virtual host configured for foo.example.com, but that only listens on port 80.
I have the A record for foo.example.com pointing to this same server. If I visit foo.example.com in my browser, it loads the Virtual Host for example.com. How can I combat this?
More posts by @Goswami781
1 Comments
Sorted by latest first Latest Oldest Best
This is because you have not setup the SSL for the sub domain foo.example.com and so it uses the domain. If you do not want SSL you can simply remove the Virtual Host all together running on port 443, otherwise just add to the configuration the following:
Allow foo.example.com to operate on SSL
<VirtualHost *:443>
ServerName foo.example.com
DocumentRoot /var/www/foo.example.com/htdocs
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
Redirect HTTPS to HTTP
<VirtualHost *:443>
ServerName foo.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^foo.example.com
RewriteRule ^/(.*)$ foo.example.com/ [L,R=301]
DocumentRoot /var/www/foo.example.com/htdocs
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
Or if you want a 404 Error then use:
<VirtualHost *:443>
ServerName foo.example.com
RewriteEngine on
Redirect 404 /
ErrorDocument 404 "Page Not Found"
DocumentRoot /var/www/foo.example.com/htdocs
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.