One droplet, 2 domains, but second domain loads to the first domain. What did I do wrong?

September 27, 2018 460 views
Apache WordPress Ubuntu 18.04

I set up a droplet using the Wordpress one click install and configured the virtual host for logancollman.com, which works great! Now the problem lies with me adding a second domain, hempyhq.com. I followed the same documentation to add the virtual host for this second domain, but somehow when visiting hempyhq.com (http://, www, etc), it simply loads logancollman.com instead of hempyhq.com’s index file.

This is the document I’ve followed:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04

I have two virtual host conf files, one for each domain, with the same configuration on each (other than the domain used).
Any idea where I could have messed this up?

EDIT:
Just found that if I go directly to https://hempyhq.com/index.php that it loads the correct domain, but the content of logancollman.com.

Also, I noticed that the path to index.php that the above URL loads is actually the index in logancollman.com, given that the index located at hempyhq.com is an index.html.

2 Answers
unixynet September 27, 2018
Accepted Answer

Hi Logan,

HTTPS is a tricky protocol.

If you have setup a domain with SSL (in this case logancollman.com) set to resolve to the server’s main IP. And then add another domain ( https://hempyhq.com/ ) without assigning a valid SSL for this second domain. Visiting https://hempyhq.com/index.php (https) will always resolve to the first vhost in the web server’s configuration, which happens to be logancollman.com.

That’s because Apache doesn’t know about the actual host header until it completes the SSL handshake and decrypts the host header for hempyhq.com. But the latter doesn’t have a valid SSL. So it can’t decrypt (chicken and egg situation). So it defaults to the first virtual host in the Apache configuration.

So you have two options:

  1. Setup a valid SSL for hempyhq.com and use Apache (with SNI)

  2. Move hempyhq.com to its own IP

You need to use separate document roots for two domains. It sounds like both your domains are pointing the same folder.

Feel free to reach me with the info on my profile page if you need assistance.

Have another answer? Share your knowledge.