- Asked 2/10
- 2074 Bhadra · 5+5 marks
- 2073 Bhadra · 4+6 marks
Virtual hosting types; name-based steps
Short answer
Types: IP-based (separate IPs), port-based (different ports), name-based (HTTP Host header). Major steps for name-based: create DNS records, DocumentRoot, <VirtualHost *:80> blocks with ServerName, then restart Apache.
Explain different types of web virtual hosting mechanism with an example. Write down the major steps while configuring named based virtual hosting.
Types of web virtual hosting
Web virtual hosting means running many web sites (domains) on one physical server. There are three mechanisms.
| Type | Distinguished by | IPs needed | Example |
|---|---|---|---|
| IP-based | Destination IP address | One IP per site | 192.168.1.10 -> site A, 192.168.1.11 -> site B |
| Port-based | TCP port number | One IP, many ports | www.a.com:80, www.a.com:8080 |
| Name-based | Host header of the HTTP request | One IP for all sites | www.a.com and www.b.com on 192.168.1.10 |
1. IP-based virtual hosting. The server has several IP addresses (several NICs or IP aliases on one NIC). Apache looks at the IP the request arrived on and serves the matching site. Works with every browser and with SSL/TLS, but wastes IP addresses.
<VirtualHost 192.168.1.10:80>
ServerName www.a.com
DocumentRoot /var/www/a
</VirtualHost>
<VirtualHost 192.168.1.11:80>
ServerName www.b.com
DocumentRoot /var/www/b
</VirtualHost>
2. Port-based virtual hosting. One IP address, each site listens on a different port. Users must type the port (http://www.a.com:8080), so it is used mainly for testing or internal sites.
Listen 80
Listen 8080
<VirtualHost *:80>
DocumentRoot /var/www/a
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /var/www/b
</VirtualHost>
3. Name-based virtual hosting. Many domain names resolve to the same IP. The browser sends the site name in the HTTP/1.1 Host: header, and the server selects the site by it. It saves IP addresses and is the most common method.
Client --GET / HTTP/1.1--> 192.168.1.10:80
Host: www.a.com |
+------+------+
/var/www/a /var/www/b
Major steps to configure name-based virtual hosting (Apache)
- Register or set up DNS: create A records so
www.a.comandwww.b.comboth point to the server IP (e.g. 192.168.1.10). On a lab network, edit/etc/hosts. - Create document roots and index pages:
mkdir -p /var/www/a /var/www/band putindex.htmlin each. - Enable name-based hosting (Apache 2.2:
NameVirtualHost *:80; Apache 2.4 does this automatically). - Write a
<VirtualHost>block for each site withServerName,ServerAlias,DocumentRootand log files.
<VirtualHost *:80>
ServerName www.a.com
ServerAlias a.com
DocumentRoot /var/www/a
ErrorLog logs/a-error.log
CustomLog logs/a-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.b.com
DocumentRoot /var/www/b
</VirtualHost>
- Check syntax:
apachectl configtest(orhttpd -t). - Restart/reload the service:
systemctl restart httpd(orapache2). - Test from a browser or
curl -H "Host: www.b.com" http://192.168.1.10/. The first block is the default site for unknown names.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- HTTP request methods; web server and virtual hosting · Internet and Intranet, chapter 4
- Short note: Web virtual hosting · Internet and Intranet, chapter 4 · asked 2×
- Virtual hosting and HTTP connections · Internet and Intranet, chapter 4
- HTTP working, methods, virtual hosting · Internet and Intranet, chapter 4
- Steps of virtual (unit) load method · Theory of Structures I, chapter 3 · asked 4×
- IC manufacturing steps; top-down F = xz + y · Embedded System, chapter 8