Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Sep 15 '11 at 6:02

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

1 Answer 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

share|improve this answer

Your Answer

 
discard

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