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

I understand the concepts of name-based virtual hosts (i.e. serving two domain names differently) and ip-based virtual hosts (i.e. a serving two ip's differently)

But...

Should I always specify an IP address, or is it OK to use *? Many examples of name-based virutal hosting still specify IP addresses. Why is VirtualHost a block and NameVirtualHost a directive? Why do I need NameVirtualHost for IP-based virtual hosts?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Should I always specify an IP address, or is it OK to use *?

You can specify * in both directives.

NameVirtualHost *    
<VirtualHost *> ...


Why is VirtualHost a block and NameVirtualHost a directive?

NameVirtualHost only defines IP on which you'll use name virtual hosts. Doesn't contain other directives, so no reason why it should be block. On the other hand VirtualHost does contain other directives for particular virtual host, so it has to be a block.


Why do I need NameVirtualHost for IP-based virtual hosts?

You don't need it. See example.


Recommended reading: Apache Virtual Host documentation

share|improve this answer
    
I still don't fully get it... In the examples I can find, the address in VirtualHost is simply a repeat of NameVirtrualHost. See for example httpd.apache.org/docs/2.2/vhosts/name-based.html#using. So it's just redundant. –  amarillion May 13 '09 at 17:15
    
True, it is redundant if the Apache listens only on one IP. But it might listen on various, differently configured. –  vartec May 14 '09 at 8:36

Your Answer

 
discard

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.