Roemer
By:
Roemer

Apache2 subdomains not working

August 29, 2014 1.6k views

Hi everyone,

I've been having a lot of issues with subdomain configuration in Apache. I've followed various tutorials but there must be something I'm doing wrong.

I want to configure talk.mydomain.com

My DNS configuration is as follows:

A
Host: @
IP: my droplets IP

A
Host: talk. (period after talk)
IP: my droplets IP

CNAME
Name: *
Hostname: @

CNAME
Name: *.talk
Hostname: talk.mydomain.com. (period)

My apache configuration is as follows (this is the configuration file for the only enabled domain. mydomain.com and www.mydomain.com work fine)

ServerName mydomain.com

<VirtualHost *:80>
ServerAdmin me@email.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/mydomain.com/public_html/talk
ServerName talk.mydomain.com
</VirtualHost>

Can anyone help me out?
Thanks in advance!

1 Answer

Hello,

The first thing that I notice is that you have a "talk" CNAME which is not needed because you are using " * to @ " which points all of your *.domain.com to your server. So you can remove the "talk" CNAME as it is not needed.

For the virtual host part I would read over the following site and follow STEP FIVE.

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts

Make sure to enable the virtual host once you complete!

Roman

by Etel Sverdlov
This tutorial shows you how to set up a new directory, how to grant the correct permissions, how to add content to a new page, how to turn on virtual hosting, and how to, if needed, set up local hosts. Virtual Hosts are used to run more than one domain off of a single IP address and allows you to run multiple sites off of a single DigitalOcean droplet. This tutorial describes how to set up virtual hosts with Apache.
  • Thanks for your reply!

    That's the tutorial I followed initially.

    I repeated step 5 and the conf file now looks like this

    
    ServerName roundpixelagency.com
    
    <VirtualHost *:80>
            ServerAdmin roemerbakker@me.com
            ServerName roundpixelagency.com
            ServerAlias www.roundpixelagency.com
            DocumentRoot /var/www/roundpixelagency.com/public_html
    </VirtualHost>
    
    <VirtualHost *:80>
            ServerAdmin roemerbakker@me.com
            DocumentRoot /var/www/mydomain.com/public_html/talk
            ServerName talk.mydomain.com
    </VirtualHost>
    

    Nothings changed though, and it still doesn't work. The host was already enabled.

  • ServerName roundpixelagency.com

    <VirtualHost *:80>
    ServerAdmin roemerbakker@me.com
    ServerName roundpixelagency.com
    ServerAlias www.roundpixelagency.com
    DocumentRoot /var/www/roundpixelagency.com/public_html
    </VirtualHost>

    <VirtualHost *:80>
    ServerAdmin roemerbakker@me.com
    DocumentRoot /var/www/mydomain.com/public_html/talk
    ServerName talk.mydomain.com
    </VirtualHost>

    You need to change that to: talk.roundpixelagency.com

  • Oh, oops, that was the wrong file actually

    I originally used that file but I got an error that was resolved by copying the file and adding .conf to the name of the file. The .conf file has the right configuration.

    I'm now getting an 404 error instead of nothing though. Ideas?

  • I got it figured out! It must have been some typo. Additionally, there must be a bug in the code because the page won't render so that's why it was blank no matter what I tried.

    Thanks!

Have another answer? Share your knowledge.