Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just dont get how my browser is able to route to correct path....when I give ServerName of a virtual host....even though it is not configured in "/etc/hosts"

Please explain me.....

This is the Virtualhost Iam talking abt

<VirtualHost *:80>
  ServerAlias example
  DocumentRoot "<*path*>"
  RailsEnv development
  <Directory "<*path*>"
    Order allow,deny
    Allow from all
share|improve this question
what is the IP of your server – LukeR Dec 11 '09 at 9:44
its on localhost – user28819 Dec 11 '09 at 10:31
That's not an IP address... – LukeR Dec 11 '09 at 10:45
I server is on local machine....i.e., – user28819 Dec 11 '09 at 11:27
I'm beginning to doubt the validity of this question being asked here. I would go out on a limb and suggest you aren't a sysadmin. – LukeR Dec 12 '09 at 2:23

The DNS server doesn't take ServerName from httpd.conf

Your browser doesn't route the request, the web server returns the correct page based in part on the Host HTTP Header sent by the browser.

When you type a URL in your browser and hit enter, the name is resolved to IP using DNS, and the browser sends an HTTP request to the IP returned from the DNS query.

HTTP headers form the core of the HTTP request. One of these is the Host, or domain name you typed in the browser.

Using an example Virtual Host definition.

<VirtualHost *:80>
  DocumentRoot /var/www/

The ServerName directive within your Virtual Host configuration is matched against the Host HTTP Header. So if you type

Apache will receive the request and try to match the Host header


with it's Virtual Host definitions. If it finds a a match, it will the use whatever is listed in the


In the example above


This could be either an index file as defined within the configuration, or a directory index if they are permitted.

share|improve this answer
Thanks for your response....but my question is before apache to get the request....IP address should get resolved right....which is done by contacting DNS server or using "/etc/hosts"....but in my case...I have apache server on my local machine and a named virtual host....when I type ServerName in my is it able to resolve....I did not add any mapping to "/etc/hosts" file.... – user28819 Dec 11 '09 at 6:56
How does it know that the ServerName entered is my local machine?? – user28819 Dec 11 '09 at 6:57
What are you typing into your browser? What is the ServerName directive? – LukeR Dec 11 '09 at 7:13
I mean to say....I submit ""; in the web browser.... My question is just...."How does IP - Domainname( mapping is done" here....though I did not change /etc/hosts – user28819 Dec 11 '09 at 8:28
I understand your question, but without specifics as to what you're typing and what your VirtualHosts config is, I can't answer it. I can guarantee if you type into a browser with an empty hosts file, it's not showing your local apache server. – LukeR Dec 11 '09 at 8:40

I believe it is actually taking it from wherever your OS is storing the hostname, /etc/hostname on Ubuntu or /etc/sysconfig/network under RH-type distros

During install, I think it fills ServerName in by running the hostname command

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.