Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk10 min

How to Point Two Domains to One VPS (NGINX and Apache Guide)

A practical guide to hosting two domains on one VPS, from DNS records and separate document roots to NGINX or Apache virtual hosts, HTTPS certificates, redirects, and troubleshooting.

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.

Yes, two domains can use one VPS and one public IP. Point each domain’s DNS A record to the VPS’s IPv4 address (and add AAAA records only when IPv6 is configured end to end). Then create a separate NGINX server block or Apache name-based virtual host for each hostname, give each site its own document root or application upstream, issue certificates covering every HTTPS name, and test both domains.

DNS only gets a request to the machine. The web server reads the requested hostname and selects the matching site. Without separate virtual-host configuration, both names may fall through to the same default site.

As an Amazon Associate I earn from qualifying purchases.

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.

What sharing a VPS actually means

A browser sends a request containing a hostname such as domain-a.example. DNS resolves that name to an IP address, the connection reaches the VPS on port 80 or 443, and NGINX or Apache chooses a configuration based on the hostname in the request. This is name-based hosting: many domains share an address while their files, application processes, logs, and certificates remain separate.

The domains do not need separate VPS instances merely because they are different names. They do need separate web-server rules if they should show different sites. Creating a virtual host does not create DNS records; DNS and web-server configuration are two independent jobs.

#1 Best Overall

Prerequisites and decisions

Gather these details before changing production DNS:

  • The VPS public IPv4 address.
  • The VPS public IPv6 address, only if the server, operating system, provider network, and firewall are all configured for IPv6.
  • Administrative access to both domains’ DNS zones.
  • sudo or root access on the VPS.
  • The web server you will use: NGINX, Apache, or an existing reverse-proxy setup.
  • A directory for each static site, or a listening address and port for each application.
  • Firewall rules allowing TCP ports 80 and 443. Keep SSH access available while making changes.
  • The complete list of names that must work, normally each apex name and its www alias.

Decide whether the apex and www name should show the same site. Usually they are listed as aliases in one virtual host and one of them is redirected to the preferred canonical name. If the two names are intended to be different sites, put them in separate server blocks or virtual hosts instead.

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

Step 1: Point both domains at the VPS

Create the apex records

At the DNS provider for each domain, create an A record for the apex (often displayed as @) containing the VPS’s public IPv4 address. If IPv6 is genuinely enabled and reachable, create an AAAA record containing the VPS’s IPv6 address. Do not publish an AAAA record for a server that cannot accept IPv6 traffic: clients that prefer IPv6 can then fail before trying IPv4.

Name Record Value When to use it
@ for domain A A VPS IPv4 address Always for IPv4 hosting
@ for domain B A VPS IPv4 address Always for IPv4 hosting
@ for either domain AAAA VPS IPv6 address Only with working IPv6 routing and firewall rules

Add the www names

For each domain, add www as either an A/AAAA pair pointing directly to the VPS or a CNAME pointing to that domain’s apex, according to the DNS provider’s rules. A CNAME cannot coexist with other record types at the same name. Whatever choice you make, include the resulting hostname in the web-server configuration and in the certificate request.

Check that DNS is answering

Use your provider’s DNS diagnostic view or a command such as dig +short domain-a.example A and dig +short domain-b.example A. Repeat with AAAA when IPv6 is enabled. The answers should be the intended VPS addresses. Existing resolver caches honor the zone’s published TTL, so some networks may continue returning the old address until that value expires.

Step 2: Give each site separate storage or an application upstream

Static sites

Create independent document roots so a deployment for one domain cannot overwrite the other:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo mkdir -p /var/www/domain-a
sudo mkdir -p /var/www/domain-b
sudo chown -R www-data:www-data /var/www/domain-a /var/www/domain-b

The web-server account differs by distribution; use the account configured for your installation rather than blindly copying www-data. Place a distinct test file such as index.html in each directory with an unmistakable title. Those markers make routing errors obvious during testing.

Applications behind a reverse proxy

Each application can listen on a different local port, for example 127.0.0.1:3001 for domain A and 127.0.0.1:3002 for domain B. The web server remains the public listener on ports 80 and 443 and forwards requests to the correct local upstream. Bind application ports to loopback unless they must be reached directly; exposing development ports publicly creates an unnecessary attack surface.

Configure two sites with NGINX

HTTP server blocks for static content

NGINX uses the server_name directive to decide which server block handles a request. Create one block per site, listing the apex and its alias together when they serve the same content:

server {
    listen 80;
    listen [::]:80;
    server_name domain-a.example www.domain-a.example;

    root /var/www/domain-a;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name domain-b.example www.domain-b.example;

    root /var/www/domain-b;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Remove the listen [::]:80; lines if this VPS has no working IPv6 listener. On Debian- and Ubuntu-style layouts, save each file under /etc/nginx/sites-available/ and enable it with symlinks in /etc/nginx/sites-enabled/. On other distributions, place the files in the include directory specified by the main NGINX configuration.

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

Proxy blocks for two applications

Replace the root and try_files section with a proxy location when a site is an application:

location / {
    proxy_pass http://127.0.0.1:3001;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

Use the second application’s port in domain B’s block. Ensure both processes are running and listening on the addresses named in proxy_pass; otherwise NGINX can match the right hostname but return a 502 error.

Validate and reload NGINX

  1. Run sudo nginx -t. Do not reload if the test reports a syntax or include error.
  2. Enable the site files if your distribution requires it, and remove or adjust the distribution’s default site so it cannot capture an unmatched request.
  3. Reload with sudo systemctl reload nginx. A reload applies valid configuration without dropping established connections.

If several blocks listen on the same address and port, an unmatched hostname goes to the default server for that listener. Make the intended fallback explicit only after the named blocks are correct; a default block should not be mistaken for a domain-specific configuration.

Configure two sites with Apache

Name-based HTTP virtual hosts

Apache’s name-based virtual hosting uses one VirtualHost container per site. Each container should have its own ServerName, optional ServerAlias, document root, and logs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:80>
    ServerName domain-a.example
    ServerAlias www.domain-a.example
    DocumentRoot /var/www/domain-a

    <Directory /var/www/domain-a>
        AllowOverride None
        Require all granted
    </Directory>

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

<VirtualHost *:80>
    ServerName domain-b.example
    ServerAlias www.domain-b.example
    DocumentRoot /var/www/domain-b

    <Directory /var/www/domain-b>
        AllowOverride None
        Require all granted
    </Directory>

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

If an application is behind Apache, use a proxy module and a distinct backend port for each site instead of a second DocumentRoot. Keep the same hostname separation: Apache still chooses the virtual host from ServerName and ServerAlias.

Enable and test Apache

  1. Save each virtual host in the configuration directory used by your distribution.
  2. On Debian- and Ubuntu-style systems, enable the files with sudo a2ensite domain-a.conf and sudo a2ensite domain-b.conf. Enable only the modules your configuration requires.
  3. Run sudo apachectl configtest. Continue only when it reports a successful syntax check.
  4. Reload with sudo systemctl reload apache2 or the service name used by your operating system.

Apache’s first matching or default virtual host can answer when no configured name matches. Check the enabled-site order and the default host if a typo or an unrecognized hostname displays the wrong content.

Secure both domains with HTTPS

Request certificates for every name

HTTPS certificates must cover every hostname that will answer securely. If users will visit both apex and www, request a certificate containing both names for domain A and another containing both names for domain B, or use a certificate strategy that explicitly covers all four names. A certificate for one domain does not validate the other merely because they share an IP address.

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

Use a trusted certificate authority and an ACME-capable client appropriate to your operating system. The HTTP challenge normally requires port 80 to reach the correct site, so keep the DNS records and HTTP listener working while issuing certificates. Store private keys with restrictive permissions and renew certificates before they expire.

NGINX HTTPS blocks and HTTP redirect

After certificates exist, add a 443 block for each site. SNI lets NGINX select the certificate and content using the requested hostname on one IP:

server {
    listen 80;
    listen [::]:80;
    server_name domain-a.example www.domain-a.example;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name domain-a.example www.domain-a.example;

    ssl_certificate     /etc/ssl/domain-a/fullchain.pem;
    ssl_certificate_key /etc/ssl/domain-a/privkey.pem;
    root /var/www/domain-a;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Create equivalent HTTP and HTTPS blocks for domain B, changing the names, certificate paths, and root or upstream. If your certificate client writes the 443 configuration automatically, inspect the generated blocks and confirm that each certificate is attached to the matching server_name.

Best Value
ZPARIK 6 Pack Guest Checks Books, Server Note Pads, Pink
  • Standard size: 6 pink server note pads, Each Book Comes with 50 bound order slips - that's 300 ticket sheets total! Check Pads Size 6.75 x 3.5 inch.
  • Convenient Work: These guest check books for servers have a tear-free dotted line that is easy to rip off. You can give as a customer copy or keep for record keeping. We've provided extra rows on the back for additional note taking.Perfect For Restaurants, Lounges, Hotels, Cafes, And Waiters To Use.
  • Record Important Information: These server note pads can record important information.Each ticket has a unique serial number printed at the top, dates, order details, number of guests, order amount, table numbers etc. They are lightweight, small and can fit most aprons. They can be used on-demand and can help decrease errors in orders, while improving work efficiency.
  • High Quality: Sturdy, Not Drop Powder, It's Thick, You Can Write On The Back And Front Easily.Their whole page printing has clear handwriting and a reasonable layout. On the customer retention part of each guest check, "THANK YOU" on the back to make customers feel appreciated.
  • Contact Us: We're confident that the quality of the server note pads will go beyond your expectation. If you experience an issue, feel free to contact us, we'll appreciate it to learn from your experience, and we'll make it better

Apache HTTPS virtual hosts

Apache needs a separate SSL virtual host for each certificate-covered name. The essential pattern is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:443>
    ServerName domain-a.example
    ServerAlias www.domain-a.example
    DocumentRoot /var/www/domain-a

    SSLEngine on
    SSLCertificateFile /etc/ssl/domain-a/fullchain.pem
    SSLCertificateKeyFile /etc/ssl/domain-a/privkey.pem

    <Directory /var/www/domain-a>
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

Repeat it for domain B with its own certificate and document root. Enable the SSL module and the HTTPS sites where your distribution requires those steps, run apachectl configtest, and reload Apache.

Redirect HTTP only after HTTPS works

Once both 443 sites answer with valid certificates, make each port-80 site return a permanent redirect to the same host and URI over HTTPS. Test the secure URL first; otherwise a redirect can turn a working HTTP site into an inaccessible one for users whose certificate or 443 configuration is incomplete.

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

Test each hostname independently

Run the checks for both domains, not just one:

curl -I http://domain-a.example
curl -I https://domain-a.example
curl -I http://domain-b.example
curl -I https://domain-b.example

For HTTP, expect the intended status or an intentional redirect. For HTTPS, verify the certificate subject/SANs, the final hostname, and the returned content. Open both apex and www names in a browser if both are published. If DNS has not propagated everywhere, test from a network that resolves the new address or use a temporary hosts-file entry on an administrator workstation; remove that override after testing.

Troubleshoot the wrong site, certificate, or response

The domain resolves to the wrong server

  • Check A and AAAA answers separately. An obsolete AAAA record can send IPv6 clients to an old machine even when the A record is correct.
  • Confirm that both names are in the intended server_name, ServerName, or ServerAlias directive, including spelling and punctuation.
  • Check that the configuration file is enabled and that the service was successfully reloaded after the change.
  • Inspect the default NGINX server or Apache virtual host when the requested hostname matches no block.
  • If a reverse proxy, CDN, or managed load balancer sits in front of the VPS, verify its origin target and forwarded-host behavior; it may hide an origin configuration error.

HTTPS presents the wrong certificate

  • Confirm that the 443 block or SSL virtual host contains the requested hostname.
  • Check that the certificate’s names include the exact apex or www name being visited.
  • Verify that the certificate and private-key paths belong to the same certificate pair and are readable by the web-server process.
  • Check SNI behavior by testing the hostname, not merely the IP address. A request made only to the IP can legitimately receive the default certificate.
  • Reload after correcting the configuration and test again from a client that is not displaying a cached certificate warning.

One site returns a 502 or connection error

For a proxied application, check that the process is running, listening on the configured local address and port, and accepting the request path. Review the NGINX or Apache error log for connection-refused, timeout, and permission messages. For static content, verify that the document root exists, contains the expected index file, and is traversable by the web-server account.

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

IPv6 users cannot connect

Remove the AAAA record until IPv6 routing, the operating-system listener, and the firewall are all correct. Alternatively, complete that configuration and ensure the web server listens on both IPv4 and IPv6. Publishing an address that only works from the VPS itself does not provide usable IPv6 service.

NGINX server blocks versus Apache virtual hosts

Decision point NGINX Apache
Hostname selector server_name in each server block ServerName and optional ServerAlias in each VirtualHost
Static files root plus location rules such as try_files DocumentRoot plus a matching Directory policy
Application routing Usually proxy_pass to a distinct local upstream Proxy modules and a distinct backend target
HTTPS Separate 443 blocks with certificate and key directives; SNI selects the name Separate SSL virtual hosts with certificate directives; SNI selects the name
Configuration check nginx -t apachectl configtest
Typical failure to inspect first Unmatched hostname falling into the default server Wrong enabled-vhost order or default virtual host

Choose the server already supported by your team and application stack. The shared-IP design is the same; the syntax, module model, log locations, and reload command differ.

Operational checklist

  • Both apex A records resolve to the VPS IPv4 address.
  • AAAA records exist only when the VPS and firewall correctly support IPv6.
  • Each published www name resolves through an A/AAAA record or an intentional CNAME.
  • Domain A and domain B have separate roots or separate application upstreams.
  • Every hostname appears in the matching NGINX or Apache configuration.
  • Port 80 and port 443 are allowed through the VPS firewall.
  • Configuration tests pass before every reload.
  • Certificates cover every apex and alias name and are attached to the matching HTTPS host.
  • HTTP redirects to HTTPS only after both secure hosts work.
  • curl -I tests return the intended response for both domains.

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 from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
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.