Set up DNS aliases with the Apache web server to point different hostnames to different directories on your web server.

What to Know

  • Edit the apache.conf (version 1) or vhosts.conf (version 2) file, then find vhosts (virtual hosts) section. Edit as per below instructions.After completing your edits, reboot the web server, then test the new configuration.

Setting up DNS Aliases​

You can create one or more directories for content within your web server’s file structure, but you can’t put them in any location on your machine. For example, most Apache server web files are located in the htdocs folder. Create a sub-folder there to host your domain files—perhaps within a www folder to segregate the content from other uses. It’s a good idea to put an index.html file in the directory so you can test later.

  • In version 1 of Apache, edit the apache.conf file and find the vhosts (virtual hosts) section.In version 2 of Apache, edit the vhosts.conf file. These configuration files are usually located in a configuration directory on your web server, not in the htdocs area.

In either version, edit the vhosts section to add a new virtual host.

Structure of a Virtual Host Entry

A typical use case involves running different hostnames that resolve to the same Internet Protocol address, and each hostname must respond differently. For example, internal.server.com may reference a company’s intranet site while www.server.com may reference its public-facing web page. To configure these examples, edit the virtual-host file as follows:

Setting DNS aliases on the web server doesn’t change DNS settings. You must still configure your DNS to map an IP address to specific hostnames.

For additional use cases for example virtual-host files, check out Apache’s documentation.

Reboot the Web Server

After completing your edits, reboot the web server, then test the new configuration.

Get the Latest Tech News Delivered Every Day