-1

I am a little confused here and after reading all over the place I haven't found an answer that matches my situation exactly.

I have been developing a large piece of software that will allow a user to access the system on their own domain name.

I am going to use domains : system.example1.com (which holds the system and can be directly accessed that way) and tester.example2.com (which will be the domain i want to access it via)

I can get all this working fine by using an A record to point tester.example2.com to the ip address of system.example1.com but I want to make this as easy as possible for system users by using a CNAME (if possible).

So as a test I created the sub domain on my domain at the registrar level (godaddy in this case) as a CNAME record like this:

CNAME tester.example2.com > system.example1.com TTL 1hr

But when I access tester.example2.com rather than seeing the system loading up as though I accessed system.example1.com directly, all I get is the apache default page.

The server is running cPanel by the way.

If I were doing this with an A record I would just park the tester.example2.com domain in cpanel, but I can't do that with a CNAME (as far as I know)

Glen
  • 119
  • 4
  • A `CNAME` will simply "redirect" you to the `A` or `AAAA` record it's pointing to, what do you expect? – sysfiend Nov 21 '16 at 17:05
  • Since system.example1.com has an A record pointing to the server, I expected the CNAME pointing to that subdomain would load up the same content as system.example1.com does, not the apache default screen. There are services I use that allow me to create a subdomain on my domain as a CNAME and point to their sub domain to load the content, that's what I am after, so then my code can determine what domain the user is using. – Glen Nov 21 '16 at 17:15
  • Oh, okey, got it now. That's probably because of a missconfiguration on the server, have a look at this: http://serverfault.com/questions/447315/issue-with-cname-and-virtual-hosts – sysfiend Nov 21 '16 at 17:18
  • Thanks, will have a read, although I tested this on two servers with different domains entirely and same issue on there – Glen Nov 21 '16 at 17:21

2 Answers2

1

A CNAME record works on the DNS level, it's an alias for a record on a different domain. That means that tester.example2.com will point to the same IP address as system.example1.com.

This does not change anything in HTTP. Your browser will do a request to tester.example2.com and NOT to system.example1.com. It will end up on the same server because of the CNAME, but if your sever does not know what to do with tester.example2.com it will show the default page.

So in addition to your CNAME, you'll also have to configure your webserver.

(Some people talk about "redirecting" when explaining a CNAME. Please do not use the word "redirect" as it just makes it harder to understand the difference.)

sorcix
  • 86
  • 1
  • Thanks, that makes total sense, so how would I then configure the server in this case to do what I need? Cpanel won't allow me to add it as an alias because the nameservers don't point to that server. – Glen Nov 21 '16 at 17:22
  • Erm.. if you have a `CNAME` in your domain, say `google.mydomain.org`, pointing to `google.com`, you'll actually see google.com – sysfiend Nov 21 '16 at 17:23
  • That's the point here though, that's all that's been done in my case though google.com here would be system.example1.com and the cname would be testing.example2.com but all I get is the apache default page – Glen Nov 21 '16 at 17:25
  • Yeah, my bad, just missunderstood the answer. Yeah, that's got to be the issue here. +1 @sorcix – sysfiend Nov 21 '16 at 17:29
  • Any suggestion on what to do? – Glen Nov 21 '16 at 17:31
  • @alex Not true. You'll see `google.mydomain.org` in your browser. You'll only see `google.com` if there is an HTTP server that does a redirect. A CNAME does nothing else than pointing to the same IP address. – sorcix Nov 21 '16 at 17:32
  • @Glen I have no experience with cpanel, sorry. – sorcix Nov 21 '16 at 17:33
  • I just figured it out, there is a setting in the WHM that disallows cpanel users from creating aliases if the domain doesn't use the same nameservers. Turned that bugger off and now all works. Thanks for your time! – Glen Nov 21 '16 at 17:34
0

As described in this cPanel thread, you can do this by temporarily enabling the "Allow Remote Domains" setting so that you can park tester.example2.com. Note that immediately afterwards, you should disable the ability to add additional remote domains.

WHM » Server Configuration » Tweak Settings, Domains tab, enable [Allow Remote Domains], add your domain, and then disable afterward.

Allow Remote Domains

Allow creation of parked/addon domains that resolve to other servers (e.g. domain transfers) This can be a major security problem. If you must have it enabled, be sure not to allow users to park common Internet domains.

More information is available in the cPanel documentation under Tweak Settings >> Domains.

For others, I'd also like to take a moment how to do this on an Apache server if it is not running cPanel. When you enter tester.example2.com in your browser, an HTTP request header of "Host: tester.example2.com" is sent to the server. Apache needs to know which application, or "VirtualHost", this request should be routed to (since Apache is designed to run multiple). Applying a directive of ServerAlias tester.example2.com inside the appropriate existing <VirtualHost> block tells Apache which application to route the request to.

sfgeorge
  • 101