Set up DNS aliases with the Apache webserver to point different hostnames to different directories on your web server.
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.
Setting up DNS Aliases
Create one or more directories for content within your web server's file structure—you can't just put them in any location on your machine. For example, most Apache server web files are located in the htdocs folder. So 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 webpage. To configure these examples, edit the virtual-host file as follows:# Ensure that Apache listens on port 80Listen 80<VirtualHost *:80> DocumentRoot "/www/intranet" ServerName internal.server.com # Other directives here</VirtualHost><VirtualHost *:80> DocumentRoot "/www/public" ServerName www.server.com # Other directives here</VirtualHost>
For additional use cases for example virtual-host files, check out Apache's documentation.
Reboot the Web Server
After you've completed your edits, reboot the web server then test the new configuration.Tips on How to Restart an Apache Web Server