Report this

What is the reason for this report?

Problems with virtual hosts configuration on apache2 ubuntu 14.04

Posted on August 7, 2020

Hi - I have various subdomains set up successfully as virtual hosts on my Digital Ocean Droplet. For some reason though, my latest subdomain is redirecting to a different subdomain, and I’m not sure why. So if you go to selingo.mikeheavers.com it shows the site for exhibitcolumbus.mikeheavers.com. Furthermore, if you just enter my droplet’s IP address (http://107.170.120.88/), it serves exhibitcolumbus.mikeheavers.com - I would expect it to just serve mikeheavers.com. What have I mixed up?

This is the contents of sites-enabled/selingo.com.conf:

<VirtualHost *:80>
        <Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ServerAdmin mheavers@gmail.com
        ServerName selingo.mikeheavers.com
        ServerAlias www.selingo.mikeheavers.com
        DocumentRoot /var/www/selingo/public_html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        LogLevel warn rewrite:trace8

        RewriteEngine On
        RewriteCond %{SERVER_NAME} =selingo.mikeheavers.com
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

and this is the contents of exhibitcolumbus.mikeheavers.com.conf:



<VirtualHost *:80>
        <Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        #ServerName www.example.com
        ServerName exhibitcolumbus.mikeheavers.com
        ServerAlias www.exhibitcolumbus.mikeheavers.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/exhibitcolumbus/public_html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        LogLevel warn rewrite:trace8

RewriteEngine on
RewriteCond %{SERVER_NAME} =exhibitcolumbus.mikeheavers.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

For both vhosts, I did a sudo a2ensite for the .conf file. I also logged into my control panel and created an ‘a’ record for each subdomain pointing to my IP for the droplet.

I noticed this in /etc/hosts:

127.0.1.1 extra extra
127.0.0.1 localhost
~

I’m not exactly sure what the top one does. I don’t remember setting that up.

Anyone have an idea of where I’ve gone wrong or how to fix / investigate?



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.

Hi there @heaversm,

The Vhost looks correct. I could suggest a couple of things:

  • Make sure that Apache has read permissions to the /var/www/exhibitcolumbus/public_html directory.

  • Check the Apache error log for some more information:

  1. tail -100 /var/log/apache2/error.log
  • If you are using a CMS like WordPress for example, make sure that the site and the home URLs are setup correctly to match your domain name.

Regards, Bobby

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.