---
title: "Short note: Web virtual hosting"
subject: "Internet and Intranet"
chapter: 4
key: "semester_8/internet_and_intranet:note-virtual-hosting"
source: https://www.bctengineer.com/q/semester_8/internet_and_intranet/note-virtual-hosting
site: BCT Engineering
---

# Short note: Web virtual hosting

Internet and Intranet · Chapter 4: HTTP and the Web Services

- Asked in: 2074 Magh, 4 marks; 2072 Asoj, 4 marks (asked 2 times)
- Video: [Configure Virtual Hosting in Apache web server | Learn Name, IP & Port based Virtual Hosting in 15m](https://www.youtube.com/watch?v=T0rLOzs2s_k) — Krishna's World (Krishna's TechInfo)
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/internet_and_intranet/note-virtual-hosting
- Whole chapter: https://www.bctengineer.com/md/semester_8/internet_and_intranet/chapter-4

## Question

Write a short note on 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.

## Answer

**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**

| Type | Site is selected by |
|---|---|
| IP-based | The server IP address the request arrived on |
| Port-based | The TCP port number |
| Name-based | The `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)**

```apache
<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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the main idea of web virtual hosting?
   A. Hosting several domains on one physical server so each appears to have its own server
   B. Copying one website to many servers for speed
   C. Running one website on a virtual machine in the cloud only
   D. Hiding a server's IP address from users
   Answer: A. Virtual hosting lets one physical server host many sites, cutting hardware, power and IP costs. (Key point: Purpose)

2. In name-based virtual hosting, how does the server choose which site to serve?
   A. By the IP address the request arrived on
   B. By the TCP port number
   C. By the Host: header in the HTTP/1.1 request
   D. By the client's browser type
   Answer: C. Name-based hosting reads the Host: header, so many names can share one IP and port. (Key point: Name-based hosting)

3. What is the main drawback of IP-based virtual hosting?
   A. It does not work with HTTPS
   B. It consumes a separate IP address for each site
   C. It needs users to type the port number
   D. It requires HTTP/1.1
   Answer: B. Each site needs its own IP address (NICs or aliases), which uses up addresses, though it works for all clients and HTTPS. (Key point: IP-based hosting)

4. Why is port-based virtual hosting rare for public sites?
   A. Users must type the port number, such as :8080
   B. It cannot use more than one site per server
   C. It only works with IPv6
   D. It requires a separate DNS server
   Answer: A. Sites on ports like 8080 need the port in the URL, which is inconvenient for public users. (Key point: Port-based hosting)

## Related in Internet and Intranet

- [HTTP request methods; web server and virtual hosting](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Ahttp-methods-config-virtual-hosting) — Internet and Intranet, chapter 4
- [Virtual hosting types; name-based steps](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Avirtual-hosting-types-named-steps) — Internet and Intranet, chapter 4, asked 2×
- [Virtual hosting and HTTP connections](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Avirtual-hosting-http-connections) — Internet and Intranet, chapter 4
- [HTTP working, methods, virtual hosting](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Ahttp-works-methods-virtual-hosting) — Internet and Intranet, chapter 4
