0

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

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

NameVirtualHost *:443
<VirtualHost 172.17.0.122:443>
ServerAdmin [email protected]
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
</VirtualHost>

<VirtualHost 172.17.0.123:443>
ServerAdmin [email protected]
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
</VirtualHost>

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 [email protected]
       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
    </Location>


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

apache2ctl -S shows:

VirtualHost configuration: 
172.17.0.122:443 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

1
  • ... 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. Commented Mar 5, 2017 at 22:04

1 Answer 1

0

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 172.16.0.123:443. These are different addresses and Apache will not acknowledge them.

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

10
  • 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
    Commented Mar 5, 2017 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
    Commented Mar 5, 2017 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. Commented Mar 5, 2017 at 10:46
  • I added NameVirtualHost 172.17.0.122:443 and NameVirtualHost 172.17.0.123:443 but still I can't get domain2 from https :(
    – Diamonte
    Commented Mar 5, 2017 at 12:09
  • Actually I have 172.17.0.122:443 as NameVirtualHost and below that <VirtualHost 172.17.0.122:443> but when I restart / reload apache, says [warn] 172.17.0.122:443 has no VirtualHosts.
    – Diamonte
    Commented Mar 5, 2017 at 12:40

You must log in to answer this question.

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