October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Point Two Domains to the Same Website on a VPS (NGINX and Apache)

A practical guide to sharing one VPS website across two domains, covering DNS, NGINX and Apache virtual hosts, HTTPS certificates, redirects, validation, and troubleshooting.
Length11 min Posted Quest giverVGSources Team

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.

Point both domains’ A records—and AAAA records if your VPS uses IPv6—to the VPS public IP, then configure your web server to accept both hostnames. NGINX does this with server_name; Apache uses ServerName and ServerAlias. Finally, install HTTPS certificates covering every hostname and decide whether both domains remain visible or the second domain permanently redirects to one canonical URL.

What “point two domains to one website” actually involves

A domain name reaches a website through two separate layers. DNS tells a browser which server address to contact. The web server then examines the hostname in the request and chooses the site configuration that should answer. Configuring only one layer is not enough: DNS can send both names to your VPS while the server still serves the wrong site, and a virtual-host definition cannot make a name resolve if DNS points elsewhere.

As an Amazon Associate I earn from qualifying purchases.

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

Assume the primary domain is example.com, with www.example.com as an optional alias, and the second domain is second.example. Replace those names with your real domains. The same pattern works for more than two domains.

  • DNS: Create records for each hostname at the authoritative DNS service.
  • HTTP routing: Tell NGINX or Apache that the names belong to the same website.
  • TLS: Use certificates that contain every HTTPS hostname.
  • URL policy: Keep both domains active, or redirect the alternate domain to one canonical address.

Choose the URL policy before changing configuration

Both domains stay active

With this model, https://example.com/page and https://second.example/page both return the website without changing the address shown in the browser. This is useful when the domains represent genuinely different entry points, campaigns, regional names, or legacy addresses that must continue to display. Every active hostname needs correct DNS, web-server matching, and certificate coverage.

The trade-off is that search engines, analytics, cookies, and users can encounter two public URLs for the same content. If you use this model, set your application’s canonical-link policy deliberately and verify that sessions, absolute links, and redirects behave correctly on either host.

One canonical domain, one permanent redirect

Most sites choose one public domain and redirect the other. For example, every request for second.example can return an HTTP 301 response to the equivalent HTTPS URL on example.com. This consolidates bookmarks and signals that the canonical host is the destination.

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

The alternate name still needs DNS and normally needs a port-80 web-server configuration so certificate validation and the redirect can work. If your certificate automation uses an HTTP challenge, do not redirect or block /.well-known/acme-challenge/ on port 80; allow the challenge request to be served as required by your ACME client.

Step 1: Point both domains at the VPS in DNS

Find the address to publish

Use the VPS provider’s public IPv4 address for an A record. If the VPS has a publicly reachable IPv6 address and you intend to serve IPv6 traffic, publish an AAAA record as well. Do not use a private address from an internal network.

Create records for the exact hostnames

At the authoritative DNS provider for each domain, create records similar to these:

Hostname Record Value Purpose
@ (the apex) A VPS public IPv4 Resolves example.com
www A VPS public IPv4 Resolves www.example.com, if used
@ (second domain) A VPS public IPv4 Resolves second.example
Each published hostname AAAA VPS public IPv6 Optional IPv6 resolution

Some DNS control panels display the apex as @; others show the full domain. Enter the value exactly as that provider documents. If an existing A or AAAA record points to another server, replace it only when that change is intended. Remove stale records that would send some users to an old VPS.

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

A DNS change may be cached according to the record’s TTL. Test from more than one network if a change appears inconsistent. A resolver can continue returning the old address until its cached TTL expires.

Check DNS before touching the web server

From a workstation, query each name:

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

Each query should return the address you intend to use. An empty response means that record type is not published; an unexpected address usually indicates a stale record, a split-DNS setup, or that the domain’s nameservers are managed somewhere other than the panel you edited. DNS must resolve before users can reach the virtual host.

Step 2: Configure NGINX for one website and two domains

Serve the same content on both names

NGINX chooses a server block by matching the request hostname against server_name. Put every hostname that should serve the same content in one block. A minimal HTTP pattern is:

server {
    listen 80;
    server_name example.com www.example.com second.example;

    root /var/www/site;
    index index.html index.php;

    # Add your normal location rules here.
    # location / { ... }
}

Keep your existing application-specific location, proxy, PHP, access-log, and security directives; the important change is the complete server_name list and the shared document root or upstream. If you publish an IPv6 address, ensure the listener also accepts IPv6 according to your operating system and NGINX configuration, for example with an appropriate IPv6 listen directive.

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

Redirect the second domain to the canonical domain

When only example.com should remain public, use a separate port-80 block for the alternate name:

server {
    listen 80;
    server_name second.example;

    location ^~ /.well-known/acme-challenge/ {
        root /var/www/acme;
    }

    location / {
        return 301 https://example.com$request_uri;
    }
}

Keep a separate block for the canonical domain that serves the site and, if desired, redirects its HTTP traffic to HTTPS. The $request_uri variable preserves the path and query string in the redirect. If the alternate domain also has a www form, list that hostname in the redirect block or create another matching block.

Test and reload safely

Run NGINX’s configuration test before reloading:

sudo nginx -t

Only reload after the test reports a valid configuration:

sudo systemctl reload nginx

A reload applies the new configuration without intentionally stopping existing workers. If the test reports an unknown directive, duplicate default server, missing semicolon, or certificate-file error, correct that issue first rather than forcing a reload.

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

Step 3: Configure Apache for one website and two domains

Use name-based virtual hosting

Apache supports multiple names on one IP through name-based virtual hosts. Set the primary hostname with ServerName and the additional hostnames with ServerAlias:

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

    <Directory /var/www/site>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Use the directory permissions and override policy your application requires; AllowOverride All is only an example and may be broader than necessary. If the site is reverse-proxied to an application server, retain the existing ProxyPass and related directives instead of adding a static document root.

Redirect the alternate name

For a canonical URL, give the alternate hostname its own virtual host and redirect it:

<VirtualHost *:80>
    ServerName second.example
    ServerAlias www.second.example

    Alias /.well-known/acme-challenge/ /var/www/acme/.well-known/acme-challenge/
    <Directory /var/www/acme/.well-known/acme-challenge/>
        Require all granted
    </Directory>

    Redirect permanent / https://example.com/
</VirtualHost>

The challenge-location directives are illustrative; configure the path expected by your certificate automation. Ensure that the challenge remains reachable before requesting or renewing a certificate.

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

Validate Apache before reloading

Check syntax and virtual-host parsing:

sudo apachectl configtest
sudo apachectl -S

The first command should report a successful syntax check. The second helps reveal which virtual host Apache associates with each name and whether another default host is unexpectedly catching requests. Reload only after correcting errors:

sudo systemctl reload apache2

The service name can differ by distribution. Use the service name installed on your VPS rather than assuming that every operating system uses apache2.

Step 4: Enable HTTPS for every hostname

Choose certificate coverage

Any hostname that users open with https:// must appear in the certificate presented for that connection. A single certificate can contain multiple names, such as the apex, its www alias, and the second domain. Separate certificates are also possible when your automation and server layout make that easier.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Certificate arrangement When it fits What to verify
One multi-name certificate Both domains share a straightforward HTTPS configuration. Every accepted hostname is included as a certificate name and the correct certificate is attached to the server.
Separate certificates Domains have separate virtual hosts, renewal schedules, or administrative boundaries. Each HTTPS virtual host serves its own matching certificate and private key.

Understand SNI and certificate selection

Modern browsers send the requested hostname during the TLS handshake using Server Name Indication (SNI). NGINX or Apache can then select the certificate and virtual host for that name on the same IP address. SNI does not fix an incomplete configuration: the hostname still needs a matching HTTPS server block and a certificate containing that name. A missing name commonly produces a browser certificate warning or the certificate belonging to another virtual host.

Keep port 80 available for validation and redirects

Certificate automation that uses an HTTP challenge must reach the challenge URL on port 80. Configure the challenge path before issuing or renewing the certificate, then redirect ordinary HTTP requests to the canonical HTTPS URL. Do not assume that a blanket redirect automatically handles the challenge; test the exact /.well-known/acme-challenge/ path used by your ACME client.

Attach certificates to HTTPS virtual hosts

Create an HTTPS server block in NGINX or an HTTPS virtual host in Apache with the same complete hostname list used for DNS. Point the configuration at the certificate and private-key files produced by your certificate automation. For a shared-content model, all active names can be listed together. For a redirect model, configure HTTPS for the alternate name as well, then return a 301 to the canonical HTTPS URL. Otherwise, users who type the alternate HTTPS address will fail before the redirect can run.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Step 5: Validate the complete path from name to page

Verify DNS answers

Repeat the dig checks after propagation. Confirm that A and AAAA records do not point to different servers unless that split is intentional. If IPv6 is published but the VPS firewall or web server is not listening on IPv6, some users may fail while IPv4 users succeed; either complete IPv6 setup or remove the unusable AAAA record.

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.

Check HTTP behavior for each name

curl -I http://example.com/
curl -I http://www.example.com/
curl -I http://second.example/

For an active multi-domain site, expect the appropriate application response. For an alternate domain, expect a 301 whose Location points to the canonical HTTPS URL. Check both the apex and www forms if you publish both.

Check HTTPS and certificate names

curl -I https://example.com/
curl -I https://second.example/

Confirm that each request completes without a certificate warning and returns the intended status or redirect. Inspect the certificate in a browser or with your TLS inspection tooling and verify that every hostname appears in its Subject Alternative Name list. A certificate for only example.com does not cover second.example.

Confirm the server selected the intended site

Use response headers, a temporary unique test file, or application logs to distinguish the two virtual hosts. When testing a new DNS configuration before propagation, send the hostname explicitly to the VPS address with a tool that supports host-header or SNI testing; do not conclude that routing works merely because the IP responds.

Common failure modes and fixes

Both domains show the default site

Usually DNS reaches the VPS but no server block matches the requested hostname. Check spelling, trailing dots, and whether the configuration file is enabled. In NGINX, verify the name is in server_name. In Apache, verify ServerName or ServerAlias and inspect apachectl -S.

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

One domain works, the other times out

Compare A and AAAA answers. A stale record, an unconfigured IPv6 listener, a firewall rule, or DNS still delegated to another provider can affect only one name or address family. Confirm that the VPS firewall allows ports 80 and 443 and that the web server listens on the public interfaces.

HTTP works but HTTPS warns

The certificate probably omits the hostname, or the HTTPS virtual host serves a different certificate. Include every active name in the certificate request and attach the resulting files to the matching HTTPS configuration. Reload only after the configuration test succeeds.

The redirect loops

A loop occurs when the server redirects an already canonical HTTPS request back to HTTP or when an upstream proxy’s HTTPS state is not conveyed correctly. Test the redirect chain with curl -I, identify the exact Location values, and ensure the canonical HTTPS virtual host serves content rather than redirecting to itself.

Certificate renewal fails after adding a redirect

Check that port 80 is reachable and that the exact challenge path is exempted from the catch-all redirect or is served by the ACME client’s challenge handler. Test the path during renewal, then rerun the certificate automation and inspect its logs for the hostname that failed.

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

NGINX and Apache: which configuration model fits?

Decision point NGINX Apache
Hostname matching server_name selects the server block. ServerName identifies the primary name; ServerAlias adds names.
Shared content List all names in one block and use one root or upstream. List aliases in one name-based VirtualHost.
Canonical redirect Use a dedicated alternate-name block with return 301. Use a dedicated alternate-name virtual host with a permanent redirect.
HTTPS scaling SNI selects the matching certificate and server block. SNI selects the matching certificate and virtual host.
Pre-reload check nginx -t apachectl configtest and, for mapping visibility, apachectl -S

Neither server requires a separate IP for each name. Both support name-based hosting, so one VPS address can serve multiple domains as long as DNS, hostname matching, and TLS are aligned.

A repeatable checklist for future domains

  1. Decide whether the new domain remains visible or redirects to an existing canonical domain.
  2. Publish A records for the apex and any www names; publish AAAA records only when IPv6 is correctly served.
  3. Wait for DNS caches to update and confirm answers with dig.
  4. Add the hostname to NGINX server_name or Apache ServerName/ServerAlias.
  5. For a redirect policy, create a dedicated alternate-domain HTTP and HTTPS configuration.
  6. Ensure /.well-known/acme-challenge/ remains reachable on port 80 during certificate issuance and renewal.
  7. Issue or renew a certificate containing every hostname that accepts HTTPS.
  8. Run nginx -t or apachectl configtest, inspect virtual-host mappings, and reload.
  9. Test every hostname over HTTP and HTTPS, including apex and www variants.
  10. Confirm the final status codes, redirect destinations, certificate names, logs, and application behavior.

Final decision

Two domains can safely share one VPS, one public IP, and one website. DNS makes both names reach the machine; NGINX or Apache decides which configuration answers; TLS certificates make each HTTPS name trustworthy. Once those layers agree, choose one deliberate URL policy—serve both names or permanently redirect the alternate—and test every hostname, address family, protocol, and certificate after each change.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.