Skip to main content

Short note: Web virtual hosting

Short answer

Virtual hosting runs multiple web sites on one physical server, primarily via name-based Host header matching, reducing cost and IP usage. It is configured with VirtualHost blocks in Apache or server blocks in Nginx, each with its own document root and settings.

Write a short note on Web virtual hosting.

Web virtual hosting is the practice of hosting several web sites (domains) on one physical web server, so that each site appears to have a dedicated server. It cuts hardware, power and IP address costs, and is the basis of shared web hosting by ISPs and hosting companies.

Types

TypeSite is selected by
IP-basedThe server IP address the request arrived on
Port-basedThe TCP port number
Name-basedThe Host: header in the HTTP/1.1 request
  • IP-based: each site gets its own IP address (several NICs or IP aliases). Works for all clients and HTTPS but consumes addresses.
  • Port-based: one IP, sites on ports 80, 8080, ...; users must type the port, so it is rare for public sites.
  • Name-based: many names on one IP; the most common. Needs HTTP/1.1 and (for HTTPS) SNI support.

Apache example (name-based)

<VirtualHost *:80>
    ServerName www.a.com
    DocumentRoot /var/www/a
</VirtualHost>
<VirtualHost *:80>
    ServerName www.b.com
    DocumentRoot /var/www/b
</VirtualHost>

Both names point in DNS to the same IP address. Each site has its own document root, logs and configuration. IIS and Nginx (server_name) support the same idea.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Internet and Intranet chapter 4 questions →