Apache Virtual Hosts

I seem to be having a bit of trouble with virtual hosts in Apache.

I have added 127.0.0.1 www.mysite.com to my hosts file in Windows and I see my web server fine.

I then added the below to my conf file, as the very end, I don't know if it matters where it goes!

NameVirtualHost *

<VirtualHost *> 
ServerName unknown
DocumentRoot "C:/xampplite/htdocs"
</VirtualHost> 

<VirtualHost www.mysite.com> 
ServerName www.mysite.com
DocumentRoot "C:/xampplite/htdocs/mysite"
</VirtualHost> 

So what I am trying to achieve is going to www.mysite.com will bring up /mysite folder and anything else - or just going to 127.0.0.1 will default back to the main htdocs folder.

But it doesn't.

It all ends up going to the mysite folder.

Looking at the error log this occurs on start up:

[Tue Sep 13 19:45:08 2011] [error] VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results

For the record I listen to ports 80 and as lame as it is, 1337.


Solution 1:

Try this config:

DocumentRoot "C:/xampplite/htdocs/"

<VirtualHost *:80>
    ServerName www.mysite.com
    ServerAlias www.mysite.com
    DocumentRoot "C:/xampplite/htdocs/mysite"
    <Directory "C:/xampplite/htdocs/mysite">
        allow from all
        Options +Indexes
    </Directory>
</VirtualHost>

So when you use: 127.0.0.1 it will go to the default DocumentRoot ("C:/xampplite/htdocs/") and when you use www.mysite.com it will go to: "C:/xampplite/htdocs/mysite". You don't need NameVirtualHost