DNS CNAME records visibility on a web server

Have a question about DNS CNAME records and what web servers see. (unfortunately I don't have an environment where I can just test this)

if I have the following domain names:

domain1.com
domain2.com
www.domain1.com
www.domain2.com

I can create them all as A records pointing directly to the IP address and the web server sees whatever the user types in the browser and everything works as planned.

But to simplify life I'd like to create one of these as the "primary" domain name as an A record and the others as an "alias" domain name with a CNAME record.
So if domain1.com is an A record and domain2.com is a CNAME to domain1.com what does the web server see what the user types in domain2.com ?
Does it see domain2.com or domain1.com ?

Does it depend on the type of web server?
Or does DNS just work it's magic in resolving the domain names to an IP and the web server doesn't know anything about it?
LVL 2
AnthonyWalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
I believe your question contains its own answer:  "... the web server sees whatever the user types in the browser."

The HTTP request structure is independent of how the IP address is resolved.  The HOST field is generated by the browser and sent as part of the GET structure.

GET /docs/index.html HTTP/1.1
Host: www.nowhere123.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
(blank line)

Open in new window


This HTTP request can be sent to any web server, regardless of whether the host is actually "www.nowhere123.com".

When the browser user enters "www.something.com", it considers whatever its own system's DNS resolver returns to be correct.  It then goes ahead and constructs the GET request with "www.something.com" and sends it off to the IP address returned by the resolver.  What the web server gets is what the browser stuck into the HOST field.

If a complicated DNS resolution across multiple names causes problems for the server then it can be instructed to accept aliases, e.g. Apache:

# ServerName: The primary name for this virtual host
# ServerAlias: Other acceptable names for this virtual host
# UseCanonicalName:  Use ServerName to build URLs referring to itself
#
ServerName www.myservername.com
ServerAlias myservername.* www.myservername.* server2.* www.myserver2.*
UseCanonicalName on

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AnthonyWalkerAuthor Commented:
Thanks, that's what I hoped would be happening.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DNS

From novice to tech pro — start learning today.