Question

Apache virtual host issue with multiple domain

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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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!