0

I have two domains setup on a single server using Apache Virtual Hosts. The first domain (domainA.com) is loading the index.html file of the second domain (domainB.com), even though the first domain (domainA.com) has an index.html file in the document root.

The virtual hosts files look to be setup correctly and I have run the following commands after creating them:

  • sudo a2ensite domainA.com
  • sudo a2ensite domainB.com
  • sudo a2dissite 000-default.conf
  • sudo apache2ctl configtest
  • sudo systemctl reload apache2
  • sudo systemctl restart apache2

Domain A virtual host file

<VirtualHost *:80>
  ServerName www.domainA.com
  ServerAlias domainA.com *.domainA.com
  ServerAdmin hello@domain.com
  DocumentRoot /var/www/domainA.com

<Directory /var/www/domainA.com>
  DirectoryIndex index.html index.php
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

  ErrorLog ${APACHE_LOG_DIR}/domainA.com_error.log
  CustomLog ${APACHE_LOG_DIR}/domainA.com_access.log combined
</VirtualHost>

Domain B virtual host file

<VirtualHost *:80>
  ServerName www.domainB.ca
  ServerAlias domainB.ca *.domainB.ca
  ServerAdmin hello@domain.com
  DocumentRoot /var/www/domainB.ca

<Directory /var/www/domainB.ca>
  DirectoryIndex index.html index.php
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

  ErrorLog ${APACHE_LOG_DIR}/domainB.ca_error.log
  CustomLog ${APACHE_LOG_DIR}/domainB.ca_access.log combined
  
  # Added when creating Let's Encrypt SSL for domain using certbot 
  RewriteEngine on
  RewriteCond %{SERVER_NAME} =domainB.ca [OR]
  RewriteCond %{SERVER_NAME} =www.domainB.ca
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Output from sudo apache2ctl -S

VirtualHost configuration:
  *:443 domainB.ca (/etc/apache2/sites-enabled/domainB.ca-le-ssl.conf:2)
  *:80 is a NameVirtualHost
    default server www.domainB.ca (/etc/apache2/sites-enabled/domainB.ca.conf:1)
    port 80 namevhost www.domainB.ca (/etc/apache2/sites-enabled/domainB.ca.conf:1)
    alias domainB.ca
    wild alias *.domainB.ca
    port 80 namevhost www.domainA.com (/etc/apache2/sites-enabled/domainA.com.conf:1)
    alias domainA.com
    wild alias *.domainA.com
    ServerRoot: "/etc/apache2"
    Main DocumentRoot: "/var/www/html"
    Main ErrorLog: "/var/log/apache2/error.log"
    Mutex rewrite-map: using_defaults
    Mutex ssl-stapling-refresh: using_defaults
    Mutex ssl-stapling: using_defaults
    Mutex ssl-cache: using_defaults
    Mutex default: dir="/var/run/apache2/" mechanism=default 
    Mutex watchdog-callback: using_defaults
    PidFile: "/var/run/apache2/apache2.pid"
    Define: DUMP_VHOSTS
    Define: DUMP_RUN_CFG
    User: name="www-data" id=33
    Group: name="www-data" id=33

Each domain is using Cloudflare for DNS, with A records for @ and www pointing to the same IP address at Digital Ocean.

There are no .htaccess files implemented on either domain.

I have similar multi domain setups using the same server and DNS configurations at Digital Ocean and Cloudflare that do work, so I am lost on why this is not.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
Mike Hermary
  • 131
  • 7

1 Answers1

1

From the output of your apache2ctl -S command it looks like you have defined VirtualHosts for both domains for port 80, but only for domainB for port 443.

Listed config files:

  • domainB.ca-le-ssl.conf
  • domainB.ca.conf
  • domainA.com.conf

You need to define a VirtualHost with SSL for domainA as well.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • I had not created a SSL config for domainA because there was a conflict with Cloudflare handling the DNS. When I ran certbot, it said the A/AAAA records were not properly set, even though they were. When I changed it to DNS only for the two A records and created the SSL config, the issue seemed to be resolved. This is still different from my other setups, so I am still a bit confused. – Mike Hermary Jul 21 '22 at 15:29