APACHE - Files - Name Based Virtual Hosting


- Info:

- This file is used to configure name based virtual hosting.

- Name based virtual hosting allows you to access the same Apache instance using different domain names in URL.

- This file is used only if httpd.conf has parameter NameVirtualHost defined.


- Example:

- http://people.com:8080/test.html

- Web Browser looks in client's C:\WINDOWS\system32\drivers\etc\hosts file for people.com.

- Web Browser then sends HTTP Request to IP mapped to people.com which is

- Web Browser inserts people.com in HTTP Request under Host header.

- HTTP Request arives on machine at port 8080.

- Apache is listening for HTTP Requests on port 8080 as defined in httpd.conf with parameter Listen 8080.

- Apache is told to use name based virtual hosting for requests arriving at port 8080 as defined in httpd.conf with

parameter NameVirtualHost *:8080.

- Apache looks for people.com virtual ServerName in httpd-vhosts.conf.

- Apache then uses /opt/application/bps as root directory where it will start searching for test.html.


HTTP Request

GET / HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*

Accept-Language: hr

UA-CPU: x86

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.1)

Host: people.com

Connection: Keep-Alive

Cookie: __utma=152158142.953685578.1251368071.1251368071.1251368071.1

hosts people.com


Listen 8080

NameVirtualHost *:8080


<VirtualHost *:80>

ServerName people.com

DocumentRoot /opt/application/bps



Hello from Apache