How to Set Up a DNS Alias With Apache

Serving Multiple Domains from an Apache Web Server

It's easy to set up DNS aliases with the Apache web server. What this means is that if you have one web domain or 100 you can set them all up to point to different directories on your web server and host them all yourself.

Difficulty: Hard

Time Required: 10 minutes

Setting Up DNS Aliases​

  1. Create a directory on your Apache web server.
    Be sure to put the directory within your web server directories, and not 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. It's a good idea to put an index.html file in the directory so you can test later.
  1. 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 are usually located in a configuration directory on your web server, not in the htdocs area.
  2. In either version, edit the vhosts section to add a new virtual host:
    IP_ADDRESS>
    ServerName DOMAIN NAME
    DocumentRoot FULL_PATH_TO_DIRECTORY
    Change the highlighted portions of the code above to the information specific to your site and domain.
  3. Restart Apache.
  4. Edit your named.conf file
  5. Add an entry for the domain:
    zone "DOMAIN" IN {
    type master;
    file "LOCATION_OF_DB_FILE";
    allow-transfer { IP_ADDRESS; };
    };
    Change the highlighted portions of the code above to the information specific to your site and domain.
  6. Create the db file for the domain
    The simplest way is to copy other db files and add your new domain.
  7. Reload your DNS
  8. Test your domain in your web browser.
    It can take several hours for your DNS to propagate, but as long as you're pointing to your local DNS you should be able to test right away.

    What You Need

    • Apache Web Server
    • Named DNS
    • Access to conf files
    Format
    mla apa chicago
    Your Citation
    Kyrnin, Jennifer. "How to Set Up a DNS Alias With Apache." ThoughtCo, May. 9, 2017, thoughtco.com/set-up-dns-alias-3466279. Kyrnin, Jennifer. (2017, May 9). How to Set Up a DNS Alias With Apache. Retrieved from https://www.thoughtco.com/set-up-dns-alias-3466279 Kyrnin, Jennifer. "How to Set Up a DNS Alias With Apache." ThoughtCo. https://www.thoughtco.com/set-up-dns-alias-3466279 (accessed December 14, 2017).