Mobile app version of vmapp.org
Login or Join
Goswami781

: 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

@Goswami781

Posted in: #Apache #HttpdConf #Https #Virtualhost

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Goswami781

1 Comments

Sorted by latest first Latest Oldest Best

 

@Radia820

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>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme