Code: DNS Domain Aliasing Using CNAMEs

Chapter 9 - Advanced Web Performance Optimization

CNAMEs make one hostname an alias of another, and take the following form:

nickname [optional TTL] class CNAME canonical-name

For example:

images1.example.com IN CNAME www.example.com
images2.example.com IN CNAME www.example.com
...

where IN indicates Internet, and CNAME indicates CNAME record.

The preceding records indicate that images1.example.comimages2.example.com are aliased to www.example.com. Note that you must also have an A record that points www.example.com to an IP address.

For example:

www.example.com. IN A 10.1.1.1

These records are stored in a "zone" file on your DNS server. In addition, the web server needs to be configured to respond to your new CNAME address. The VirtualHost and ServerAlias configuration directives are often stored in the httpd.conf file.

For example:

<VirtualHost 10.1.1.1:80>
    ServerName images1.example.com
    ServerAlias images2.example.com
    DocumentRoot /var/www/images
    ServerAdmin webmaster@example.com
    CustomLog /var/log/httpd/images1.example.com combined
</VirtualHost>