Pcornel
Browse topics
Options
Recent
Favorites
Web Infrastructure · Technical reference

Virtual Hosts

Direct answer

Virtual hosts let one web server serve several sites, selected by host name (Host header and TLS SNI), IP address or port.

When to use this

Use it when hosting several sites on one server, or when the wrong site appears for a name.

First 30 seconds

1. curl -vI https://<name> — which site and certificate?

2. Apache apachectl -S / Nginx nginx -T — name in a vhost?

3. DNS points the name to this server?

4. Certificate SAN includes the name?

5. Define an explicit default vhost that returns 404/444.

Operational verification

client sends Host/SNI → server matches a virtual host → serves its content and certificate

Evidence · next step

For Web Services → Virtual Hosts, continue with the first unproven Topic check: Pin destination IP/port, requested hostname, scheme/SNI, expected site and config enablement path. If that boundary is healthy, advance to the adjacent check: Inspect effective listener and vhost/server ordering rather than file presence alone. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when hosting several sites on one server, or when the wrong site appears for a name.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

listener → TLS SNI if used → Host header → server/vhost precedence → site root/proxy policy → response

Healthy evidence: the requested name resolves to the expected listener and deterministic vhost/server selection yields the intended certificate, document root or upstream

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Pin destination IP/port, requested hostname, scheme/SNI, expected site and config enablement path.

  • Inspect effective listener and vhost/server ordering rather than file presence alone.
  • Test with the exact Host/SNI from both local and real-client paths and correlate logs.
  • Fix only the selection cause, then retest the original hostname and a sibling/default site.

Verification chain. listener → TLS SNI if used → Host header → server/vhost precedence → site root/proxy policy → response

Step 3 Commands Verify boundary
apachectl -S
nginx -T | grep server_name
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: default site captures traffic, duplicate names/listeners create surprising precedence, SNI and Host disagree, DNS points elsewhere, or tests omit the real Host header

Step 5 Common mistakes Narrow the fault
  • Overlapping server names between vhosts.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

If no virtual host matches the name, the default (first or explicitly marked) answers — often showing another site. Each HTTPS site needs a certificate matching its name (SNI).

Key checks
  • systemctl status nginx|apache2|httpd — web server state
  • nginx -t / apachectl configtest — configuration test
  • ss -ltnp | grep -E ':80|:443' — listening ports
  • curl -vI https://<name> — response, headers and TLS
  • tail -f /var/log/nginx/error.log — error log (or apache2/httpd)
ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

Virtual-host configuration is confirmed when the real request selects the intended site under both TLS and HTTP routing rules, not merely when the site definition exists.

In depth

Virtual hosts: many sites on one server

Virtual hosting serves several sites from one server. The Apache documentation on name-based virtual hosts describes the two approaches:

  • IP-based hosting needs one address per site.
  • Name-based hosting relies on the host name the client sends, so many sites share one address. The documentation recommends it, unless equipment explicitly requires IP-based hosting.

Apache first finds the most specific <VirtualHost> for the address and port. Among those, it compares ServerName and ServerAlias with the requested name, and uses the first listed vhost when nothing matches. It also advises always setting ServerName explicitly.

Name matching in Apache and nginx

RuleApachenginx
Exact nameServerName www.example.netserver_name www.example.net;
Several namesServerAlias example.net *.example.netserver_name example.net *.example.net;
Wildcards* and ? in ServerAliasLeading or trailing *, or regular expressions (~^...$)
Unknown namesThe first listed vhost for the addressThe default_server, or the first server

HTTPS and SNI

With TLS, the server must choose a certificate before it sees the HTTP Host header. SNI (Server Name Indication) sends the name in the TLS handshake, so name-based virtual hosting works for HTTPS too. nginx's HTTPS guide notes that SNI is mandatory to implement in TLS 1.3, and that only domain names are reliable in SNI, not IP addresses.

A layout that scales

PracticeReason
One file per siteEnable or disable a site independently
An explicit default site that rejects unknown namesNothing is served under names you didn't configure
Separate logs per siteEasier analysis and rotation
The same names in the certificate (SAN) and the configurationNo certificate warnings
host$ cat /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
    ServerName default.invalid
    DocumentRoot /var/www/empty
    Redirect 404 /
</VirtualHost>
host$ cat /etc/apache2/sites-available/intranet.conf
<VirtualHost *:80>
    ServerName intranet.example.net
    ServerAlias intra.example.net
    DocumentRoot /srv/www/intranet
    ErrorLog ${APACHE_LOG_DIR}/intranet-error.log
    CustomLog ${APACHE_LOG_DIR}/intranet-access.log combined
</VirtualHost>
host$ sudo a2ensite intranet && sudo apachectl configtest && sudo systemctl reload apache2
host$ sudo apachectl -S 2>&1 | grep -E "namevhost|default server"
         default server default.invalid (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost default.invalid (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost intranet.example.net (/etc/apache2/sites-enabled/intranet.conf:1)
host$ curl -s -o /dev/null -w "%{http_code}\n" -H "Host: intra.example.net" http://localhost/
200

Reading apachectl -S

The 000- prefix makes the empty default site load first, so it becomes the default for port 80. Requests for unknown names get a 404, instead of the intranet site. apachectl -S confirms which vhost is the default, and lists every name it answers for.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Virtual Hosts is part of Web Services → Virtual Hosts. Virtual Hosts maps multiple web identities to shared listeners using request attributes such as address/port, Host and often TLS SNI; diagnosis must show which site actually wins selection.

Topic-specific state model. Virtual Hosts maps multiple web identities to shared listeners using request attributes such as address/port, Host and often TLS SNI; diagnosis must show which site actually wins selection.

Interpretation rule. - A vhost file exists ≠ it is enabled or selected.

  • DNS resolution to the server ≠ the correct virtual host is selected.
  • Correct Host routing over HTTP ≠ correct TLS SNI/certificate selection.
  • One hostname working ≠ other names sharing the listener are unaffected.

Quick reference

Name-based virtual hosts serve several sites from one IP, selected by the Host header (and SNI for TLS).

server {
    listen 443 ssl;
    http2 on;
    server_name app.example.com;
    ssl_certificate     /etc/letsencrypt/live/app.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;
    root /srv/www/app;
    access_log /var/log/nginx/app.access.log;
}
server { listen 80; server_name app.example.com; return 301 https://$host$request_uri; }

Apache equivalent: <VirtualHost *:443> ServerName app.example.com … </VirtualHost>; apachectl -S shows which vhost answers each name. Always define an explicit default server so unknown names don't land on a real site.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Virtual-host configuration is confirmed when the real request selects the intended site under both TLS and HTTP routing rules, not merely when the site definition exists.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Virtual Hosts owns site-selection semantics across Apache/Nginx; server-specific syntax remains in their Topics.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Web Services → Virtual Hosts. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://nginx.org/en/docs/ · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
virtual hostsvhostserver blocks virtual hosts
Embedded reference data

Quick lookup tables

Virtual Hosts operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Virtual Hosts.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateVirtual Hosts maps multiple web identities to shared listeners using request attributes such as address/port, Host and often TLS SNI; diagnosis must prove which site actually wins selection.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin exact client/server + time + request/file operation → identify authoritative configuration → read back effective service/listener/session state → trace protocol selection/auth/identity → verify backend/upstream boundary → correlate logs → make smallest persistent change → repeat original workload + regression check.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainlistener → TLS SNI if used → Host header → server/vhost precedence → site root/proxy policy → responseTrace requested/configured state through effective state to the observed workload result.
Failure boundaryVirtual-host configuration is proven when the real request selects the intended site under both TLS and HTTP routing rules, not merely when the site definition exists.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux web/file-service evidence can establish this proof path: listener → TLS SNI if used → Host header → server/vhost precedence → site root/proxy policy → responseUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove unobserved clients, names, identities, routes, sessions, backends or time periods. Virtual-host configuration is proven when the real request selects the intended site under both TLS and HTTP routing rules, not merely when the site definition exists.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven service boundary, capture adjacent effective state and protocol/application evidence, make only the demonstrated persistent change, then repeat the original client workload plus a regression check.Continue to the next unresolved boundary while preserving the original test condition.

Virtual Hosts · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryVirtual Hosts
Topic pathWeb Services → Virtual Hosts
Runtime stateVirtual Hosts maps multiple web identities to shared listeners using request attributes such as address/port, Host and often TLS SNI; diagnosis must prove which site actually wins selection.
Fast checks- Pin destination IP/port, requested hostname, scheme/SNI, expected site and config enablement path. - Inspect effective listener and vhost/server ordering rather than file presence alone. - Test with the exact Host/SNI from both local and real-client paths and correlate logs. - Fix only the selection cause, then retest the original hostname and a sibling/default site.
Verification chainlistener → TLS SNI if used → Host header → server/vhost precedence → site root/proxy policy → response Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundaryVirtual-host configuration is proven when the real request selects the intended site under both TLS and HTTP routing rules, not merely when the site definition exists. Boundary chain: unit config/drop-ins → dependency/order/condition → exec/process → readiness/active state → owned socket/file/device → dependent client/workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?