---
title: "Virtual hosting and HTTP connections"
subject: "Internet and Intranet"
chapter: 4
key: "semester_8/internet_and_intranet:virtual-hosting-http-connections"
source: https://www.bctengineer.com/q/semester_8/internet_and_intranet/virtual-hosting-http-connections
site: BCT Engineering
---

# Virtual hosting and HTTP connections

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

- Asked in: 2071 Bhadra, 2+8 marks
- Video: [How Name Based Virtual Hosting Works in HTTP Connection](https://www.youtube.com/watch?v=aHer3IZBmQc) — thinkvatsa
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/internet_and_intranet/virtual-hosting-http-connections
- Whole chapter: https://www.bctengineer.com/md/semester_8/internet_and_intranet/chapter-4

## Question

What is virtual hosting? Explain the HTTP connections with respect to web access.

## Short answer

Virtual hosting serves multiple domains on one server using IP, port, or the Host header (name-based). HTTP connections may be non-persistent (separate TCP per object, ~2 RTT) or persistent (keep-alive, pipelining reduces total delay to ~1 RTT).

## Answer

#### Virtual hosting

**Virtual hosting** is hosting more than one web site (domain name) on a single web server machine, so that each site appears to have its own server. It reduces cost and IP address use. The methods are IP-based, port-based and name-based (the server picks the site from the HTTP `Host:` header). Example in Apache: two `<VirtualHost *:80>` blocks with `ServerName www.a.com` and `ServerName www.b.com`.

#### HTTP connections

A web page has a base HTML file plus many objects (images, CSS, scripts). How TCP connections are used for them matters for delay.

**1. Non-persistent connection (HTTP/1.0 default)**
- A separate TCP connection is made for **each** object and closed after the response.
- Each object costs 2 RTT (one for TCP handshake, one for request/response) plus transmission time.
- Browsers can open several parallel connections to reduce delay, but this loads the server and network.

**2. Persistent connection (HTTP/1.1 default)**
- The server leaves the TCP connection open after replying (`Connection: keep-alive`) and closes it after a timeout or on `Connection: close`.
- Several objects use the same connection, saving handshakes and slow-start.
  - **Without pipelining:** the client sends a new request only after receiving the previous response; about 1 RTT per object.
  - **With pipelining:** the client sends requests back-to-back without waiting; as little as about 1 RTT for all objects.

```text
 Non-persistent             Persistent
 SYN/SYN-ACK  (RTT)         SYN/SYN-ACK  (RTT)
 GET obj1     (RTT)         GET obj1 / obj2 / obj3
 close                      ... same connection ...
 SYN/SYN-ACK  (RTT)         close after timeout
 GET obj2     (RTT)
```

| Point | Non-persistent | Persistent |
|---|---|---|
| Connections for n objects | n | 1 (or few) |
| Delay per object | ~2 RTT | ~1 RTT or less |
| Server resources | More (many sockets) | Less |

HTTP/2 goes further by multiplexing many requests on one connection.

## Check yourself

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

1. What is the point of virtual hosting?
   A. Run several web sites on one server machine, reducing cost and IP use
   B. Cache pages at the edge
   C. Encrypt HTTP
   D. Assign IPs dynamically
   Answer: A. Multiple domains share one machine, so each site appears to have its own server while saving hardware and addresses. (Key point: Virtual hosting benefit)

2. In a non-persistent connection, what is the cost per object?
   A. About 1 RTT with no handshake
   B. About 2 RTT plus transmission time, since each object needs a new TCP connection
   C. 0 RTT
   D. 1 RTT total for all objects
   Answer: B. One RTT for the TCP handshake plus one for request/response, repeated for each object. (Key point: Non-persistent cost)

3. What does pipelining in a persistent connection allow?
   A. The client sends requests back-to-back without waiting for responses
   B. The server sends before being asked
   C. Each object uses a new connection
   D. Requests are sent over UDP
   Answer: A. With pipelining, all objects can be obtained in as little as about 1 RTT, versus about 1 RTT per object without it. (Key point: Pipelining)

4. Which connection type is the default in each version?
   A. HTTP/1.0 persistent, HTTP/1.1 non-persistent
   B. HTTP/1.0 non-persistent, HTTP/1.1 persistent
   C. Both persistent
   D. Both non-persistent
   Answer: B. HTTP/1.0 closes the connection after each object by default, while HTTP/1.1 keeps it open (keep-alive). (Key point: Default HTTP versions)

## 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
- [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
- [Short note: Web virtual hosting](https://www.bctengineer.com/question.md?key=semester_8%2Finternet_and_intranet%3Anote-virtual-hosting) — Internet and Intranet, chapter 4, asked 2×
- [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×
