Wildcard CNAME not working?

September 9, 2014 6.9k views

I have set up my DNS and all appeared to be working fine, I have 2 sites hosted on my server using virtual hosts and going to either http://domain1.com or http://domain2.com works. However going to http://www.domain1.com or http://www.domain2.com does not. I have set up both a wildcard and www CNAME in the hopes of fixing it but it still doesn't work.

My droplet is running CentOS 6 and apache, I have copy/pasted the info i have on the dns control panel below with the ip/domains removed. Any help or pointers to where I'm going wrong would be great!


A @ xxx.xxx.xxx.xxx

CNAME www @





Zone File

$TTL 1800
@ IN SOA NS1.DIGITALOCEAN.COM. hostmaster.mydomain.com. (
1409133661 ; last update: 2014-08-27 10:01:01 UTC
3600 ; refresh
900 ; retry
1209600 ; expire
1800 ; ttl
@ IN A xxx.xxx.xxx.xxx

  • Could you post your Apache config for the virtual hosts?

  • Here it is:

    <VirtualHost *:80>
    DocumentRoot /var/www/html
    <Directory /var/www/html >
    AllowOverride All
    Order allow,deny
    Allow from all

    <VirtualHost *:80>
    DocumentRoot /var/www/html/stmatts
    ServerName domain1.com
    ServerAlias *.domain1.com www.domain1.com

    <VirtualHost *:80>
    DocumentRoot /var/www/html/anvildigital
    ServerName domain2.co.uk
    ServerAlias *.domain2.co.uk www.domain2.co.uk

2 Answers

Hi !

I could see your DNS question, and I may give you a few help to check what is going on.

Using a CNAME records in DNS presumes that you are pointing to a Fully Qualified Domain Name, as it is a record used to point to Canonical Names only.

In your typical case, you are trying to point a CNAME to your domain '@' which can only point an IP. As far as I know that kind of records, I would not use that kind of CNAME in my DNS zone file.

You can solve this issue in 2 ways :

  • You could point the 'www' subdomain to the PTR record of your IP address, and match the FQDN requirements to use a CNAME in your record. The digitalocean admin panel allows you to do so once you've booted a container, and this could be the solution

  • You could use a second A record to point your 'www' subdomain to the same IP as your domain. This solution is less sexy as it will need you update your DNS zone file twice each time an IP changes in your design. But this is an acceptable solution if you don't want to fix PTR for all the containers you will create in DigitalOcean admin panel.

I hope this information could help you. Feel free to let me knows if it was OK to issue your case ;)

Best regards,


  • Hi,

    Removing the DNS record and adding the www as an A record has worked, however I would rather use CNAME. I was a little confused by your instructions on using the CNAME, could you post an example?


  • Hi,

    Here is how to use CNAME record for your www subdomain.

    The good pratices says CNAME are used for canonical names, and mostly respresents Fully Qualified Domains Name hosts. So, if you want to use CNAME, you will need to add an A record that will point to your VPS hostname.

    For example, lets say your webserver was called 'Foo', and your domain is 'domain.com'.
    If you want to configure your domain name, and use CNAME for your www subdomain, you will need the following record :

    www IN CNAME foo

    When declaring your hostname 'foo' with a A record, then foo.domain.com will be recorded. If you add the proper PTR record in DO droplet panal to match foo.domain.com with the IPOFDROPLET, then your foo.domain.com is a FQDN hosts : DNS resolution matches your IP for foo.domain.com, and inverse DNS resolution on your IP matches your hosts as well ^^.

    In that kind of configuration, you just need tu update the hostname IP when it changes, and the CNAME record for 'www' will make maintenance easier.

    I hope my explanation was not too confusing, as I added the FQDN notion needed for MX records in my response. But the most important to remember is that CNAME are used for canonical names, and need a record of the type 'foo.domain.com' that needs to point to a A record ;)

    Have a good day !!



  • Thanks, that worked a treat!

Have another answer? Share your knowledge.