0

I can't configure two domains with VirtualHost, because, always show me only one domain. I mean, if I visit domainB.com that redirect me to domainA.com and domainA.com works fine. I made this procedure in anothers hosts like: DigitalOcean or my own localhost, but with this instance I can't find the issue. If I disable one site the other works without problem.

I have a google instance with Ubuntu 17.10 and Apache2 with two domains (virtualhost). I disabled the default virtualhost. My folder structure is /var/www/domainA/ and /var/www/domainB/

Cloud DNS is configured with two zones domainA.com and domainB.com with A and CNAME records point to my server IP. I have too NS records pointed to googledomains.com and in my registar I added those DNS.

If I do a ping to both domains, them resolve correctly to my IP address without problem.

I have the two domains configured in sites-available:

#in /etc/apache/sites-available/domainA.com.conf
<VirtualHost *:443>
        ServerAdmin webmaster@domainA.com
        ServerName domainA.com
        ServerAlias www.domainA.com
        DocumentRoot /var/www/domainA

        ErrorLog ${APACHE_LOG_DIR}/error-domainA.log
        CustomLog ${APACHE_LOG_DIR}/access-domainA.log combined

        SSLEngine on
        SSLCertificateFile /etc/apache2/sslcert/certified-number.crt
        SSLCertificateKeyFile /etc/apache2/sslcert/domainA.com.key
        SSLCertificateChainFile /etc/apache2/sslcert/gd_bundle-g2-g1.crt

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /var/www/domainA/>
            Options FollowSymLinks
            AllowOverride All
        </Directory>

        <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
        </Directory>
</VirtualHost>

#in /etc/apache/sites-available/domainB.com.conf
<VirtualHost *:80>
        ServerAdmin webmaster@domainB.com
        ServerName domainB.com
        ServerAlias www.domainB.com
        DocumentRoot /var/www/domainB

        ErrorLog ${APACHE_LOG_DIR}/error-domainB.log
        CustomLog ${APACHE_LOG_DIR}/access-domainB.log combined

        <Directory /var/www/domainB/>
                Options FollowSymLinks
                AllowOverride All
        </Directory>
</VirtualHost>

Result of apachectl -S command:

sudo apache2ctl -S

VirtualHost configuration:
*:80                   domainB.com (/etc/apache2/sites-enabled/domainB.conf:1)
*:443                  domainA.com (/etc/apache2/sites-enabled/domainA.conf:1)
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 mpm-accept: using_defaults
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

What other setting I must to check?

UPDATE INFORMATION: If I try with www for the domainA, works fine.

  • www.domainA.com -> Works
  • domainA.com -> Doesn't work, redirect to domainB.com
  • www.domainB.com -> Works
  • domainB.com -> Works
Jose Ayram
  • 198
  • 1
  • 14
  • 2
    Do you need to access domainA.com over http as well as https? In this case you will need to add a separate VirtualHost for domainA.com listening on port 80 in addition to the one on port 443. Probably it should redirect to the https host. The two ports have completely separate VirtualHost lists. – Matt Raines Aug 01 '19 at 13:47
  • Thanks @MattRaines. I added that setting like you describe and it works fine. – Jose Ayram Aug 01 '19 at 13:52

1 Answers1

1

I had only a VirtualHost configuration in the port 443 for domainA.com.

I added a configuration *:80 with a redirection to ssl and works. Like this:

<VirtualHost *:80>
        ServerAdmin webmaster@domainA.com
        ServerName domainA.com
        ServerAlias www.domainA.com
        Redirect / https://www.domainA.com/
</VirtualHost>

Thanks Matt Raines for his comment.

Jose Ayram
  • 198
  • 1
  • 14