Base domain not responding after subdomains and certs added

April 7, 2018 313 views
DNS Ubuntu

I'm running Ubuntu LAMP on 16.04

I set up a base domain and www subdomain with SSL certs and they worked fine.

Then I added several subdomains with their own directories and their own SSL certs. They all work fine.

However, after adding the subdomains, base domain does not seem to reference its own directory. The www subdomain still works fine.

To see what I'm talking about
http://www.teamifi.net <-- this will redirect to https, and will load the site as intended
http://bensranch.teamifi.net <-- this will redirect to https, and will load the placeholder index.html as intended
http://teamifi.net <-- this redirects to https, which fails, and for some reason it loads the placeholder index.html from the bensranch subdomain.

Here are the conf files for each:

For teamifi.net (the directory is /var/www/teamifi.net/public_html/)
This is teamifi.net.conf

<VirtualHost *:80>
        ServerAdmin steve.teamifi@gmail.com
        DocumentRoot /var/www/teamifi.net/public_html
        ServerName teamifi.net
        ServerAlias www.teamifi.net

#        <Directory /var/www/html/>
#            Options Indexes FollowSymLinks
#            AllowOverride All
#            Require all granted
#        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =teamifi.net [OR]
RewriteCond %{SERVER_NAME} =www.teamifi.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

This is the teamifi.net-le-ssl.conf

IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin steve.teamifi@gmail.com
        DocumentRoot /var/www/teamifi.net/public_html
        ServerName teamifi.net
        ServerAlias www.teamifi.net

#        <Directory /var/www/html/>
#            Options Indexes FollowSymLinks
#            AllowOverride All
#            Require all granted
#        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/teamifi.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/teamifi.net/privkey.pem
</VirtualHost>
</IfModule>

For bensranch.teamifi.net (the directory is /var/www/ifi-bensranch/)
This is ifi-bensranch.conf

<VirtualHost *:80>
        ServerAdmin steve.teamifi@gmail.com
        DocumentRoot /var/www/ifi-bensranch
        ServerName teamifi.net
        ServerAlias bensranch.teamifi.net

#        <Directory /var/www/html/>
#            Options Indexes FollowSymLinks
#            AllowOverride All
#            Require all granted
#        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =bensranch.teamifi.net [OR]
RewriteCond %{SERVER_NAME} =teamifi.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

This is ifi-bensranch-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin steve.teamifi@gmail.com
        DocumentRoot /var/www/ifi-bensranch
        ServerName teamifi.net
        ServerAlias bensranch.teamifi.net

#        <Directory /var/www/html/>
#            Options Indexes FollowSymLinks
#            AllowOverride All
#            Require all granted
#        </Directory>

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

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

SSLCertificateFile /etc/letsencrypt/live/bensranch.teamifi.net/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/bensranch.teamifi.net/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

It feels like a configuration, alias, redirect or some similar issue, but I hate to go just changing configs willy-nilly.
Would be glad to receive any insight or assistance the community might have.

Thanks,
-- se

1 Answer
eubie67 April 7, 2018
Accepted Answer

Nevermind. I figured it out. In the config files for the subdomains, the ServerName has to be the full subdomain rather than just the base domain.

        ServerAdmin steve.teamifi@gmail.com
        DocumentRoot /var/www/ifi-bensranch
        ServerName teamifi.net
        ServerAlias bensranch.teamifi.net

Should be ...

        ServerAdmin steve.teamifi@gmail.com
        DocumentRoot /var/www/ifi-bensranch
        ServerName bensranch.teamifi.net
        ServerAlias bensranch.teamifi.net

Once I made that change to all the subdomain conf files, the base domain started working again as intended.

-- se

Have another answer? Share your knowledge.