Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting software on my server that allows users to point their domain to using CNAME

Tags:

cname

I am creating software that allows users to either have their own custom subdomain (e.g: theirsubdomain.mydomain.com) or point a CNAME from their own domain to my website address (e.g: theirsubdomain.theirdomain.com).

I've contacted my host about this and the first subdomain option is cool. They will set-up a wilcard subdomain script for me...

The CNAME they said I can't do automatically. I will have to manually go into my account and add the domain to point to my website address otherwise apache wont now where to look for the files.

Is this common practice or is there a way around this that is automated?

like image 496
Ben Sinclair Avatar asked Mar 25 '10 05:03

Ben Sinclair


People also ask

What is host for CNAME?

CNAME is responsible for the aliases of a real host name given to a computer, CNAME stands for Canonical Name Records. CNAMEs are important when a DNS server points multiple domain names to the same IP address.

Can CNAME point to another domain?

CNAME records must point to another domain name, never to an IP address. A hostname defined in a CNAME record must have no other resource records of other types (MX, A, etc.), except for DNSSEC records like RRSIG and NSEC.

Can a CNAME point to a subdomain?

When you configure a CNAME record for a subdomain, DNS queries are no longer sent for the subdomain but for the domain or subdomain specified in the CNAME record to the appropriate name server. You can add a CNAME record to your subdomain in the Domains section of the Control Panel.


1 Answers

The issue is the HTTP header. When you request a Web page the browser sends a request that starts out with:

GET /mypage.html HTTP/1.1
Host: www.mysite.com

The Host item allows a single Web server to serve pages for multiple domains. By looking at the Host, the server knows that mypage.html should come from its stored files for mysite.com, and not from the files of myothersite.com which is on the same server.

I am guessing your site is on a shared Web server at your host company, and they use this functionality to differentiate between requests for your site and requests for other sites that sit on that same virtual box. Some of these virtual hosts, like HostGator, will allow you to specify other domains that should be accepted on this Host line and where the returned documents should come from. This often is a more premium service offered by companies. For example on HostGator they say "The Baby and Business hosting plans allow for unlimited domains to be hosted on just one single account", however the basic Hatchling plan does not allow this.

If you have your own rented machine, with your own installation of Apache, you can manage the processing of this HTTP header information yourself. Apache supports virtual hosts, see the following documentation: http://httpd.apache.org/docs/2.2/vhosts/

So basically, you have to have some way to tell Apache (or whatever server you are using) that the files for a particular Host value corresponds to the same files for your domain, since a single Apache server may be providing files hundreds of different domains. If you are not administering your own Apache server, to where you can set up virtual hosts as shown in the documentation, the hosting service would have to provide some custom way to get this information to Apache.

like image 182
jowo Avatar answered Oct 29 '22 16:10

jowo