Report this

What is the reason for this report?

Base domain not responding after subdomains and certs added

Posted on April 7, 2018

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



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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.