Apache virtual host issue with multiple domain

July 12, 2019 135 views
Apache Ubuntu 18.04

let's say i have 2 domain and 1 ip address

  1. domain-one.com
  2. domain-two.com

my virtualhost configuration for domain-one.com :

<VirtualHost *:80>
    ServerName domain-one.com
    ServerAlias www.domain-one.com

    DocumentRoot /var/www/domain-one.com/html
</VirtualHost>

<VirtualHost *:443>
    ServerName domain-one.com
    ServerAlias www.domain-one.com

    DocumentRoot /var/www/domain-one.com/html
    SSLEngine on
    SSLCertificateFile *ssl_location*
    SSLCertificateKeyFile *ssl_location*
    SSLCertificateChainFile *ssl_location*
</VirtualHost>

and virtualhost configuration for domain-two.com :

<VirtualHost *:80>
    ServerName domain-two.com
    ServerAlias www.domain-two.com

    DocumentRoot /var/www/domain-two.com/html
</VirtualHost>

It works, but when i visit using ip address without https , apache will using domain-two.com virtualhost

and when i visit using ip address with https, apache will using domain-one.com virtualhost

the question is , is that possible using DocumentRoot /var/www/html when i visit ip address?

1 Answer

Why did you bring up a third site at /var/www/html? Is this site enabled too?

To check, run the following command:

grep -R "DocumentRoot" /etc/apache2/sites-enabled

Does the output list anything about /var/www/html? If not, then the site at /var/www/html is not enabled and therefore will not effect your other 2 sites.

Next question: Does domain-two.com also have an SSL config file?

I’ve seen issues before related to this. You may need one.

Lastly, I didn’t see in your example configs the RewriteEngine on directive. You’ll need this.

Good luck!

Have another answer? Share your knowledge.