payments
By:
payments

Map CNAME a subdomain to other subdomain on droplet

July 29, 2014 3.3k views

I am hosting 2 domains on one centos droplet. And I want to alias subdomain of domain one to a subdomain of domain two. Like this.

I want to use subdomain.domain1.com as alias to subdomain.domain2.com, so that subdomain.domain1.com shows content of subdomain.domain2.com.
How to do that.

I have added this in DNS section of domain1.com
CNAME subdomain subdomain.domain2.com.

But it's not working. subdomain.domain1.com points to error page. It should show website on subdomain.domain2.com

1 comment
2 Answers

The CNAME record should look like this (on domain1.com):

subdomain.domain1.com points to error page

Can you post the exact error you get?

Yes, that's what I did. in DNS section of domain1.com added CNAME entry

subdomain subdomain.domain2.com.

But subdomain.domain1.com shows default centos/apache page. http://oi58.tinypic.com/547k35.jpg

I have also waited an hour, thought DSN might not have propagated so far. But it's same result.

  • That's fine, it means the subdomain is pointing to your other droplet. The next step is to configure Apache to serve the contents of subdomain.domain2.com when a request for subdomain.domain1.com hits it.

    To do that, open your VirtualHost config file in your favorite editor and add the following line under ServerName subdomain.domain2.com:

    ServerAlias subdomain.domain1.com
    

    If you already have a ServerAlias directive in your VirtualHost config, simply add subdomain.domain2.com to the existing alias(es) separated by a space:

    ServerAlias another.domain.com subdomain.domain1.com
    

    Finally, restart Apache2 for the changes to take effect:

    sudo service apache2 restart
    
  • That was it.
    It's working now.

    Thanks a lot.

Have another answer? Share your knowledge.