I have apache serve setup with example domains domain1.com and domain2.com

My ssl.conf (etc/apache2/modes-enabled/ssl.conf)

NameVirtualHost *:443
ServerAdmin info@domain1.com
DocumentRoot /var/www/domain1.com/htdocs
ServerName domain1.com:443
SSLEngine On
SSLProtocol all
SSLCertificateFile    /var/ssl/domain1/domain1.crt
SSLCertificateKeyFile /var/ssl/domain1.key
SSLCertificateChainFile /var/ssl/intermediate.crt

ServerAdmin info@domain2.com
DocumentRoot /var/www/domain2.com/htdocs/
ServerName domain2.com:443
SSLEngine On
SSLProtocol all
SSLCertificateFile    /var/ssl/domain2/domain2.crt
SSLCertificateKeyFile /var/ssl/domain2.key
SSLCertificateChainFile /var/ssl/intermediate.crt

domain1 works fine with http and https, domain2 works only with http, since domain2 https shows domain1 page... I have 2 ips on server.

VirtualHost (etc/apache2/sites-enabled/domain1.com) for domain1:

<VirtualHost *>
        ServerAdmin info@domain1.com
       ServerName  www.domain1.com
        ServerAlias domain1.com

    # Indexes + Directory Root.
    DirectoryIndex index.php
    DocumentRoot /var/www/domain1.com/htdocs/

    # CGI Directory
    ScriptAlias /cgi-bin/ /var/www/domain1.com/cgi-bin/
    <Location /cgi-bin>
            Options +ExecCGI

    # Logfiles
    ErrorLog  /var/www/domain1.com/logs/error.log
    CustomLog /var/www/domain1.com/logs/access.log combined

apache2ctl -S shows:

VirtualHost configuration: www.domain1.com (/etc/apache2/mods-enabled/ssl.conf:77)
 wildcard NameVirtualHosts and _default_ servers: 
*:* is a NameVirtualHost default server www.domain3.com (/etc/apache2/sites-enabled/domain3.com:1) 
port * namevhost www.domain3.com (/etc/apache2/sites-enabled/domain3.com:1)
port * namevhost www.domain2.com (/etc/apache2/sites-enabled/domain2.com:1)
port * namevhost www.domain1.com (/etc/apache2/sites-enabled/domain1.com:1)

this is with config that shows domain1 https corectly

  • ... Good grief. Search all your config files for NameVirtualHost stanzas and make sure none of them overlap. Especially that *:* one is damning and probably the root cause. – Shadur Mar 5 '17 at 22:04

Remove the :443 from the ServerName stanzas. It's treated as part of the name, and when no VirtualHost ServerName entry matches, Apache serves up the first VirtualHost site it finds.

EDIT d'oy. Also, take a good look at your NameVirtualHost statement as it contrasts with your VirtualHost stanzas.

You're announcing there will be multiple VHosts using the address *:443, but then specify your VHosts on These are different addresses and Apache will not acknowledge them.

Either change your NameVirtualHost statement or amend your <VirtualHost> stanzas so that they match.

| improve this answer | |
  • I removed :443, also I edited question and added original * virtualHost for first domain which works fine for non https. tho still domain2 serve domain1 from https – Diamonte Mar 5 '17 at 9:49
  • So i need NameVirtualHost for both ips:443? Does apache need this for http aswell? If http works fine for now – Diamonte Mar 5 '17 at 10:19
  • You can only have VirtualHosts on addresses specified in a NameVirtualHost entry. If you're not sure, set them all to *:443. – Shadur Mar 5 '17 at 10:46
  • I added NameVirtualHost and NameVirtualHost but still I can't get domain2 from https :( – Diamonte Mar 5 '17 at 12:09
  • Actually I have as NameVirtualHost and below that <VirtualHost> but when I restart / reload apache, says [warn] has no VirtualHosts. – Diamonte Mar 5 '17 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.