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

Apache newb here. I've read a few tutorials and I'm not sure what I'm doing wrong.

I have my default site enabled, and that one works fine:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128


So I wanted to add a second site, I updated my hosts file:   sam-NV53    # Added by NetworkManager   localhost.localdomain   localhost
::1 sam-NV53    localhost6.localdomain6 localhost6   sam-NV53 localhost.localdomain localhost

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

And I defined my new website

<VirtualHost *>

    DirectoryIndex index.html
    DocumentRoot /var/www/

Since the DocumentRoot for my new site is the same as the one for my default site, I'd expect to see the index.html from my default site. But instead, I see the from the web. What am I missing here?


Apparently nobody has noticed that my entry in my hosts file is backwards. I changed it to:

Now it works. Thanks everyone for your input :)

share|improve this question

migrated from Sep 11 '11 at 2:35

This question came from our site for professional and enthusiast programmers.

Thanks for the tip Jim. – Samo Sep 11 '11 at 2:27

whatever is in your


must match with what you have listed for


So if you have

 NameVirtualHost *:80

All your virtualhost entries for port 80 must look like

<VirtualHost *:80>

So switch * to *:80 like is in your first example and it should go to the correct place

share|improve this answer

Try using something other than,, or other derivatives. Those names are reserved by IANA for use in documentation. I used my own Apache server to try configuring a virtual host at, and I ALWAYS got redirected to the IANA page, but then I changed it to and everything was fine.

Best of luck

share|improve this answer
Thanks for the tip. Unfortunately, that didn't do the trick. Can you think of anything I might be doing wrong? – Samo Sep 11 '11 at 2:33
@Samo your /etc/hosts looks fishy. Is an actual IP of a machine on your network? Also, as is associated with your machine's loopback network adapter, you may not get the behavior you wanted. I suggest you change to your machine's IP address (most likely according to your posted /etc/hosts). – rjacks Sep 11 '11 at 3:28
@Samo, also, as @uesp suggested, having the document root on both hosts set to the same directory might be causing an issue. Why don't you point the second host at /var/www/test and set up a trivial index.html in that directory? It will certainly make debugging a bit easier – rjacks Sep 11 '11 at 3:35

A few things you can try:

  1. As rjacks mentioned, don't use for your site's name.
  2. Don't add an entry to your hosts file. This may be useful in some cases but I don't see how it is needed in this case.
  3. Update your DNS to point the new server name to your web server's IP. For example, if you own you can freely create a sub-domain or any number of other ones as desired.
  4. Make sure you restart Apache after any changes to its configuration file.
  5. I would serve the new web site to another directory than the default site, at least temporarily, in order to confirm which VirtualHosts was actually matching and serving it.
share|improve this answer
Editing /etc/hosts can be useful for people like me who are just playing around with a server in their house before purchasing a domain, hosting, etc. For example, I edited /etc/hosts on my laptop to point to my development server on my home LAN. I assume the poster is in a similar position. – rjacks Sep 11 '11 at 3:31

I've tried this using virtualbox. Host OS - Win7, Guest OS - Ubuntu Server.

1) create in /etc/apache2/sites-available/

<virtualhost *:80> # i recommend adding your interface IP here
    DirectoryIndex index.html
    DocumentRoot /var/www/main/htdocs
    LogLevel warn
    ErrorLog /var/www/main/logs/error.log
    CustomLog /var/www/main/logs/access.log combined

2)create directories inside /var/www

mkdir -p /var/www/main/htdocs
mkdir -p /var/www/main/logs

modify permissions for those directories

3) enable site in apache2


4) edit /etc/apache2/sites-available/default and remove all lines between DocumentRoot and the last line.

5) restart or reload apache2

6) edit your hosts file then try it out.

This worked on my test server.

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.