What's actually requested when alias is set up in Apache with CNAME?

Solution 1:

This is generally a good idea, as you point out you only have to change the IP in one place now.

The client would look-up test1, get pointed to default, then get the IP. It would then connect to Apache and tell Apache that it wants the test1 site (it does not tell the server how it found the server, just what the original request is).

Solution 2:

You've identified one key advantage to the CNAME record.

As far as apache goes, the HTTP header Host field will remain whatever was entered into the client and the CNAME will have no effect.

One possible downside to CNAME is that looking up a record that has a CNAME entry will require two queries, first to get the CNAME and second to get the A record. This is probably not a big deal but worth mentioning.

Finally, be careful with "chaining CNAMEs," that is creating a CNAME to a CNAME. While it is permissible under the RFC, it is discouraged.

Solution 3:

To answer your last question: If you are using NameVirtualHost directive in Apache, and have a vhost set up for each CNAMEed entry, you will get unique pages as defined by that vhost.

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName test1.example.com
    DocumentRoot /var/www/test1
</VirtualHost>

Generally speaking From my experience, I'd recommend that you don't depend on the default configuration for any live content, and instead set up a vhost (with serveraliases if required) for each name. There are always exceptions, but this is generally easier to debug because every name that you are hosting is accounted for by being explicitly defined in the config.