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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

You can host many domains on one machine and one public IP by using name-based virtual hosting. DNS sends each hostname to the server; Apache or NGINX then reads the request hostname and selects that site’s configuration, files, or application upstream. Give every public name its own routing block, define a deliberate fallback for unknown names, and provision HTTPS certificates that cover each hostname.

How one server serves several websites

A browser request contains a destination address and a hostname such as example.com. DNS resolves that name to your server’s IPv4 or IPv6 address. Once the connection arrives, the web server chooses a virtual host (Apache) or server block (NGINX) by matching the hostname, listener address, and port.

Each site can have an independent document root, access policy, log files, TLS certificate, or reverse-proxy destination. Capacity is workload-dependent: there is no universal limit on the number of sites one server can support.

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

Prerequisites and deployment plan

  • A running server with Apache HTTP Server or NGINX installed and administrative access.
  • One or more registered domain names and control of their DNS records.
  • Directories containing each site’s files, or reachable upstream applications for proxied sites.
  • Firewall and upstream network access for the ports you intend to expose, normally 80 and 443.
  • A plan for permissions, logs, backups, updates and certificates for every site.
  1. Create a separate content root (or upstream target) for each hostname.
  2. Create DNS records that point every hostname to the server’s public address. Add both A and AAAA records only when IPv4 and IPv6 are actually reachable.
  3. Ensure Apache or NGINX listens on the required address and port.
  4. Add one site-specific configuration block per hostname.
  5. Validate the configuration with the server’s checker, then reload it using your operating system’s supported service workflow.
  6. Test each hostname, an unknown hostname, and HTTPS from outside the server’s network.
  7. Issue certificates and configure HTTP-to-HTTPS behavior after plain HTTP routing works.

Apache: configure one VirtualHost per site

Apache name-based hosting uses a <VirtualHost> block. Set an explicit ServerName and DocumentRoot in every block; add ServerAlias for additional names such as www. The following is an illustrative HTTP shape, not a tested, distribution-specific deployment:

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

<VirtualHost *:80>
    ServerName example.net
    DocumentRoot /var/www/example.net
</VirtualHost>

Adapt paths, permissions, logging, TLS directives and your distribution’s include or site-enablement conventions. A block can contain normal file serving directives or proxy rules for an application instead of a document root.

How Apache chooses a block

Apache first narrows candidates by destination IP address and port. If several candidates remain, it compares ServerName and ServerAlias. When no name matches, the first listed virtual host for that address-and-port set becomes the fallback. Omitting ServerName can therefore produce surprising matches.

Validate and inspect Apache

Use your distribution’s syntax check before reloading. Then run:

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

This displays Apache’s parsed virtual-host map, including address/port groups, names and the default order. If a domain shows the wrong content, compare this output with the hostname and listener you intended.

NGINX: configure one server block per site

NGINX places server blocks inside the http context. Normally each block declares listen and one or more server_name values:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.html;
}

server {
    listen 80;
    server_name example.net;
    root /var/www/example.net;
    index index.html;
}

This is a routing pattern only. Adjust roots, indexes, access controls, logging, upstream proxy directives, TLS settings and the files included by your operating system. For an application, replace or supplement root with the appropriate proxy_pass or other upstream configuration.

NGINX name matching and fallback

NGINX checks exact names first, then wildcard names, then regular expressions. Exact names are preferable when possible; regular expressions are evaluated sequentially and can be slower. If no name matches, NGINX uses the default server for that port: normally the first server listed, unless a block is explicitly marked default_server. Define a safe default so an unknown hostname cannot expose another site’s files.

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.

After editing, run the installed NGINX syntax checker (commonly nginx -t) and reload through your platform’s service manager only when the check succeeds. Inspect the loaded configuration and compare each block’s listen, server_name and default setting with the request you are testing.

Large name lists

If NGINX reports a server-name hash construction error, then consider its documented server_names_hash_max_size or server_names_hash_bucket_size directives. Do not add this tuning pre-emptively; first correct exact names and wildcards and change the hash settings only in response to the startup error.

Apache and NGINX compared

Decision Apache HTTP Server NGINX
Per-site unit <VirtualHost> block server block inside http
Hostname directives ServerName; optional ServerAlias server_name
Listener Address and port in <VirtualHost>; the daemon must listen there listen directive
Unknown-name fallback First vhost for the matching address and port First server for the port, unless default_server is set
Hostname matching Address/port candidates, then names and aliases Exact, wildcard, then regular-expression names
Useful check apachectl -S Loaded configuration plus documented matching order

Neither configuration pattern is categorically faster or easier from these routing rules alone. Choose according to your existing modules, deployment workflow and application requirements.

DNS, ports and public reachability

Virtual-host configuration does not create DNS. For every public hostname, create the required A and/or AAAA record at your DNS provider and wait for caches to expire. Verify that both records lead to the same intended server and that IPv6 is configured if an AAAA record exists. Firewalls, cloud security groups and any upstream load balancer must permit the web ports you use.

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

Before debugging Apache or NGINX, query DNS from an external network and request each hostname with its correct Host header. A name resolving to another address can make a correct server configuration appear broken.

HTTPS and certificate selection

HTTPS adds hostname selection during the TLS handshake. Clients send the requested name through SNI; Apache or NGINX uses it to select the TLS virtual host and certificate. Configure a certificate whose names cover every hostname in that site’s HTTPS block, including aliases you actually publish.

HTTP-01 validation

Let’s Encrypt HTTP-01 retrieves a challenge file over HTTP and can only use port 80. Ensure external traffic reaches the correct site and challenge path before requesting the certificate. Port 80 can redirect ordinary visitors to HTTPS while still serving the challenge.

DNS-01 validation

DNS-01 proves control with a TXT record under _acme-challenge. It supports wildcard certificates and does not require inbound access to the web server, but automated DNS credentials must be narrowly scoped and protected. Allow time for TXT-record propagation.

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

Certificate tools commonly provide Apache, NGINX and webroot integrations; follow the instructions for your installed version and distribution rather than copying enablement paths between systems.

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

Troubleshooting wrong sites and failed certificates

Both domains display the same files

  • Confirm each DNS name resolves to the intended address, including IPv6.
  • Check spelling and aliases against Apache’s ServerName/ServerAlias or NGINX’s server_name.
  • Verify both blocks are included and loaded, then reload after a successful syntax check.
  • Check that the request uses the expected port; HTTP and HTTPS have separate listener and certificate blocks.

An unknown hostname exposes a real site

Inspect Apache’s first vhost for the address/port or NGINX’s default server for the port. Create an intentional fallback that returns an error or a neutral page instead of relying on file ordering.

The HTTPS certificate is wrong

Confirm the client sends SNI, that the name appears in the certificate’s SAN list, and that the TLS block for that name is actually loaded on port 443. A correct HTTP block cannot fix a missing or misordered HTTPS block.

Certificate validation fails

  • For HTTP-01, test external port-80 reachability and make sure redirects, proxies and virtual-host matching deliver the challenge file unchanged.
  • For DNS-01, inspect the exact TXT value at _acme-challenge and wait for propagation; remove stale competing values when your certificate client requires it.

Apache appears to ignore a host

Run apachectl -S and compare the parsed names and address/port groups with the request. A missing include, typo, duplicate alias or unintended first vhost usually explains the result.

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

NGINX will not start after adding names

Run the syntax checker to obtain the precise error. If it is a server-name hash construction failure, correct names first and then apply the documented hash-size directives. Do not mask unrelated syntax or permission errors with hash tuning.

Or skip the browser setup

If your goal is repeatable screenshots of the sites you have just routed, ScreenshotNeo provides a single HTTP request instead of maintaining browser automation. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

Example cURL request (see the ScreenshotNeo API documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

The same endpoint works from Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo includes full-page and selector captures, device presets, retina scale, PDF output, custom CSS and JavaScript, waits, request blocking, headers, cookies, geolocation, caching, signed links, asynchronous webhooks, bulk capture and a usage API. Every feature is on every plan: 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.

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.

FAQ

Do I need a separate IP address for every domain?

No. Name-based hosting is designed for multiple hostnames sharing one address, provided DNS and the web-server listener route the names correctly.

Can one site’s requests go to an application instead of files?

Yes. Keep the hostname-specific block, but configure its request handler as a reverse proxy to that site’s upstream application rather than serving a document root.

What happens when a client sends no hostname?

The server uses its fallback behavior for the selected address and port. Treat that fallback as an explicit security and usability decision.

Frequently Asked Questions

Do I need a separate IP address for every domain?

No. Name-based hosting lets multiple hostnames share one address when DNS and the web-server listener are configured correctly.

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

Can one site’s requests go to an application instead of files?

Yes. Use the hostname-specific block as a reverse proxy to that site’s upstream application.

What happens when a client sends no hostname?

The server uses the fallback for the selected address and port, so configure that fallback deliberately.

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.