7

I'm running Ubuntu 12.10 and I have the following 4 VirtualHost entries in /etc/apache2/apache2.conf

The 4 VirtualHost entries are for 2 separate sites, test.example.com and test2.example.com, one entry each for HTTP and one for HTTPS.

<VirtualHost *:443>
   DocumentRoot /var/www/test
   ServerName test.example.com
   # Other settings goes here
</VirtualHost>


<VirtualHost *:80>
   DocumentRoot /var/www/test
   ServerName test.example.com
   # Other settings goes here
</VirtualHost>

<VirtualHost *:443>
   DocumentRoot /var/www/test2
   ServerName test2.example.com
   # Other settings goes here
</VirtualHost>


<VirtualHost *:80>
   DocumentRoot /var/www/test2
   ServerName test2.example.com
   # Other settings goes here
</VirtualHost>

My problem When I save and restart apache, I get this warning:-

* Restarting web server apache2
[Sun Feb 17 18:30:09 2013] [warn] _default_ VirtualHost overlap on port 443, the first has precedence
 ... waiting [Sun Feb 17 18:30:10 2013] [warn] _default_ VirtualHost overlap on port 443, the first has precedence

And I get the contents of /var/www/test when I open both test.example.com and test2.example.com

Any idea what the problem is?

2
  • Is NameVirtualHost *:443 in your configuration?
    – faker
    Feb 17, 2013 at 18:47
  • @faker, not it was not. I added it and the problem was solved :) Thanks. If you add it as an answer, I can accept it. Also can you tell me why adding it was necessary, since I hadnt added NameVirtualHost *:80 for HTTP and still both the VirtualHosts on port 80 woked?
    – Sparky
    Feb 17, 2013 at 18:59

1 Answer 1

12

You need to add NameVirtualHost *:443 for it to work.
NameVirtualHost *:80 must also be in your configuration, it is probably set by default, but I don't use Ubuntu so I'm not sure in which file.

Also a word of advice:
Running multiple HTTPS sites on a single IP might have it's drawbacks, specifically older clients (IE8/Windows XP) will not support SNI.
It may make perfect sense in your situation (only for testing, *.example.com wildcard certificate is being used, etc.) but you should be aware of this.

2
  • I was struggling with this today, everything worked instantly after adding the line. Thank you.
    – Swimburger
    Oct 30, 2015 at 14:31
  • 1
    On my Ubuntu server I had to add this to /etc/apache2/ports.conf. In there, <IfModule mod_ssl.c> already had a Listen 443 and I added NameVirtualHost *:443 there. It also refers to some other file in the comments, but that didn't exist on my server. Run an apachectl -t to check if your configuration is correct.
    – ar34z
    Dec 9, 2015 at 8:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .