Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Point every parked hostname to the server with DNS, then configure Apache name-based virtual hosting to serve the correct content. Apache cannot create public DNS records for you. After creating the document root and virtual host, enable the site, reload Apache, run apachectl -S, and test each hostname—including an unknown name to verify the fallback virtual host.

What a parked domain means on a LAMP server

A parked domain is an additional hostname that resolves to an existing web server. It may display the same site as a primary domain, or it may have its own document root and logs while using the same Apache and Linux server. The web server is the Apache component of LAMP; DNS directs the hostname to the machine, and Apache decides which content to return after reading the request’s Host header.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

These are separate operations. A virtual-host file does not publish DNS, and a DNS record does not tell Apache which directory to serve. Both layers must agree on the hostname and address.

Two practical parked-domain models

Model Apache arrangement Isolation When to use it
Alias to an existing site Add the parked hostname to the primary site’s ServerAlias list. Shared document root, application, and usually logs. Brand aliases, campaign domains, or a domain that should show identical content.
Separate virtual host Create a new VirtualHost with its own ServerName, document root, and log files. Independent files and logs while sharing the IP and Apache process. A parked domain that will later become its own site or needs separate access and error logs.

The procedure below uses the separate-vhost model because it makes routing visible and easy to diagnose. If the domain must be an exact alias, use the alias model instead of creating a second document root.

Prerequisites and naming plan

  • A Linux server running Apache, with permission to create files under the web-server configuration and document-root directories.
  • The server’s public IPv4 address for an A record and, if the server serves IPv6, its public IPv6 address for an AAAA record.
  • The parked domain registered and access to its authoritative DNS controls.
  • A definite list of hostnames, such as example.com and www.example.com. Decide whether other names should redirect, be aliases, or remain unconfigured.
  • A plan for HTTP testing and a separate HTTPS configuration. An HTTP virtual host alone does not complete a production TLS deployment.

Use a fully qualified, explicit name in every virtual host. Leaving ServerName out can cause Apache to inherit an unintended name, making a configuration appear to work while routing requests elsewhere.

1. Create DNS records before configuring Apache

In the domain’s DNS zone, create an A record for each hostname that should resolve over IPv4. Create matching AAAA records only when the server is reachable over IPv6 and Apache is listening on that address. For the example names, the intended result is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Hostname Record Value
example.com A Your server’s public IPv4 address
www.example.com A The same server IPv4 address, unless you deliberately route it elsewhere
example.com and www.example.com AAAA The same server’s public IPv6 address, when IPv6 is configured

DNS records must already resolve to the server before Apache can match those names for public requests. A hosts-file entry is useful only for testing from the one computer containing the entry; it does not publish the domain for other users.

Check DNS from a client

Query each name and confirm that the returned address is the address on which Apache listens. Use your operating system’s DNS utility, such as:

dig +short example.com A
dig +short example.com AAAA
dig +short www.example.com A
dig +short www.example.com AAAA

If your DNS provider has not yet returned the new answer, wait for the provider and recursive resolvers to update before diagnosing Apache. A wrong DNS answer sends the request to another machine, where no local virtual-host change can help.

2. Create a document root and a test page

Create a directory dedicated to the parked site. The following path is an example; use the layout required by your Linux distribution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo mkdir -p /var/www/example.com/public_html
sudo sh -c 'printf "%sn" "Parked domain: example.com" > /var/www/example.com/public_html/index.html'

Assign ownership and permissions according to the distribution’s web-server policy. The Apache worker must be able to traverse the parent directories and read the files, while the account that deploys the site needs a controlled way to update them. Do not make the tree world-writable as a shortcut. If an application needs to write uploads or cache files, grant write access only to those specific directories.

A separate root prevents an accidental file from the primary site appearing under the parked name and gives you a clear place to inspect when routing is correct but the page is not.

3. Write the Apache name-based virtual host

Create a site configuration in the directory used by your distribution. Debian-family systems commonly keep enabled-site definitions under /etc/apache2/sites-available; other distributions may load files from a global configuration or a conf.d directory. Save the following as a file such as example.com.conf in the appropriate location.

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

What each directive does

  • <VirtualHost *:80> applies the definition to HTTP traffic received on port 80 for the addresses Apache is configured to serve.
  • ServerName is the canonical hostname Apache compares first.
  • ServerAlias adds alternate names, such as the www hostname. Add every intended alias explicitly; an alias not listed here will not match this vhost.
  • DocumentRoot selects the directory whose files are served.
  • The Directory block grants access to that root. AllowOverride All permits per-directory rules in an .htaccess file; choose a narrower setting when the application does not need overrides.
  • Require all granted allows Apache to serve the directory under Apache 2.4 authorization rules.
  • ErrorLog and CustomLog give this hostname separate diagnostics and request records. Keep log paths valid for your distribution; the APACHE_LOG_DIR variable is commonly defined on Debian-family installations.

Configuring a true alias instead

If the parked domain must display exactly the primary site’s files, do not create a second root. Add the parked names to the primary vhost’s ServerAlias directive, for example ServerAlias www.primary.example parked.example www.parked.example. Keep one canonical redirect policy in the application or rewrite rules so search engines and users are not presented with competing hostnames.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Enable the site and reload Apache

On a Debian-family system, enable the file and reload the service:

sudo a2ensite example.com.conf
sudo systemctl reload apache2

Use the equivalent site-enabling or configuration-loading command for another distribution. A reload applies a valid configuration without the interruption associated with a full stop and start. If the reload reports an error, do not continue to testing; fix the syntax or file path first.

Confirm that Apache is listening on the port you intend to use. A DNS record pointing to port 80 cannot work if a firewall blocks port 80 or Apache listens only on another address or port.

5. Inspect Apache’s parsed virtual-host map

Run the parser view before testing from the public Internet:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apachectl -S

This command dumps the addresses, ports, names, and configuration files Apache actually parsed. Check that example.com and www.example.com appear under the expected address and port, and that the file you edited is listed. This catches a configuration saved in the wrong directory, a site that was never enabled, and a typo in a name or path.

Read the default-vhost information

Apache uses name-based hosting by first selecting the best matching address and port, then comparing the request hostname with ServerName and ServerAlias. If no name matches, Apache serves the first virtual host listed for that address and port. The apachectl -S output identifies that order.

Put the intended fallback site first for each address and port. Do not rely on an accidental filename order: enabling another site or changing distribution-managed ordering can change which site receives an unknown hostname.

6. Test every hostname and the fallback behavior

  1. Query DNS for the bare domain, each alias, and any IPv6 name you published.
  2. Request the bare domain over HTTP and verify the expected test page or application appears.
  3. Request the www alias and confirm that it reaches the same vhost or the deliberately configured redirect.
  4. Test from a network that is not the server itself when possible, so local hosts-file entries do not hide a DNS problem.
  5. Send an intentionally unknown hostname to the server and observe which site responds. The response should be the fallback vhost you selected, not a site chosen accidentally.
curl -i http://example.com/
curl -i http://www.example.com/
curl -i -H 'Host: unknown-host.example' http://SERVER_IP/

Replace SERVER_IP with the server’s address. The final request is an HTTP name-routing test; it is useful when DNS for the unknown name does not exist. For HTTPS, the TLS certificate and SNI selection add another layer and must be tested with the actual hostname after certificates are installed.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why Apache can show the wrong site

The hostname is not listed

If the request name matches neither ServerName nor any ServerAlias, Apache uses the first vhost for the selected address and port. Add the exact hostname, reload Apache, and confirm it appears in apachectl -S.

DNS points somewhere else

Compare the DNS answer with the server address. Check both A and AAAA records: a stale or incorrect IPv6 record can send IPv6-capable clients to a different server even when the IPv4 record is correct.

The new file was not enabled or parsed

An edited file in a sites-available directory is inert until your distribution loads or enables it. Look for the file in apachectl -S output and reload only after syntax validation succeeds.

Virtual-host order changed

When no hostname matches, the first vhost for that address and port wins. Reorder the enabled definitions or create an explicit catch-all policy, then verify the result with an unknown-host request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The request reaches Apache but the page is inaccessible

Inspect the per-site error log. Check directory traversal permissions, the DocumentRoot spelling, the presence of an index file, and the Require all granted rule. A routing success with a 403 or 404 is a filesystem or application issue, not a DNS-selection issue.

The domain does not connect at all

Verify DNS, firewall rules, Apache’s listening address and port, and whether the server is reachable over the protocol family the client selected. A virtual-host definition cannot make a blocked port reachable.

Complete HTTPS before production use

The example above handles HTTP on port 80 only. A production parked domain needs a separate TLS virtual-host configuration on the HTTPS listener and a certificate covering every hostname users will visit, including the bare and www names when both are public. Configure certificate renewal and test renewal before relying on the domain. The certificate vendor and renewal mechanism depend on your environment and are not determined by the Apache routing configuration.

After TLS is configured, repeat the hostname tests over HTTPS. Confirm that the certificate name, virtual-host selection, redirects, and application-generated canonical URLs all agree. An HTTP vhost that works perfectly does not prove that HTTPS requests select the same site.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Operational checklist

  • Every public hostname has the intended A and, when applicable, AAAA record.
  • The parked domain’s content model is explicit: shared alias or isolated document root.
  • The vhost states ServerName, all required ServerAlias values, and the correct DocumentRoot.
  • Filesystem ownership and permissions allow Apache to read content without making the entire tree writable.
  • The configuration is enabled, successfully reloaded, and visible in apachectl -S.
  • The intended default vhost is first for each address and port.
  • The bare domain, aliases, and an unknown hostname have been tested.
  • HTTPS certificates, renewal, and TLS vhosts are configured before treating the parked domain as production-ready.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.