Linux – Subdomains not working with virtual hosts on apache2 ubuntu

apache-2.2linuxUbuntu

I'm trying to set up a subdomain on my ec2 account but can't figure out what's going on. I've looked for a few hours and haven't been able to find an answer :-/

I'm trying to set up a subdomain using virtual hosts but no matter what I try the browser can't find the subdomain 🙁

I have the following vhosts files set up:

apache2/sites-available/mysite (this site currently works)



    <VirtualHost *:80>
        ServerName mysite.com
        ServerAdmin webmaster@localhost

        DocumentRoot /home/sites/mysite

        <Directory /home/sites/mysite>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/mysite-error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined

    </VirtualHost>

apache2/sites-available/red (this is the subdomain I'm trying to set up)



    <VirtualHost *:80>
        ServerName red.mysite.com
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/red
        <Directory /var/www/red>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/red-error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/red-access.log combined

    </VirtualHost>

Apache mod_rewrite is enabled.

I've enabled both sites using a2ensite and I make sure I restart apache every time I make a change.

/etc/hosts



    127.0.0.1 localhost
    127.0.0.1 mysite.com
    127.0.0.1 red.mysite.com

Any help would be appreciated.

Thanks!

Best Answer

How to debug all similar errors:

1) make sure the domain red.whatever.com is pointing to the correct ip

How to do this? Use a tool like DIG on linux/osx or resort to an online tool.
the common error the browser reports in such a case is COULD NOT FIND DOMAIN...

2) If the IP is correct check both Apache logs (error.log and access.log)

If there is no information on these logs check your firewall to see if port 80 is open.
the common error on the browser reports in such case is COULD NOT CONNECT...

3) IP is correct, port is open, Apache is not serving the content you were expecting

The solution to your problem will be given by the log files
the browser will show a 404 or a similar http error sent by the server...

EDIT: from your comment your problem is on number 1.

Related Topic