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'm trying to understand the difference between the following two terms:

*:80
_default_:80

in the Apache configuration file. The documentation here is unclear to me, and the only mailing list conversation that I could find here does not shed any (comprehensible, to me) light on the matter either.

I have a bunch of name-based virtual hosts declared like this:

<VirtualHost *:80>
    ServerName example.com
    ...

and I'd like to have an entry that fires when none of those match, i.e. when a request comes in without a virtual host name, or with a virtual host name that has not been declared. Should I use *:80 or default:80?

share|improve this question
    
On apache you can have either one website on a single ip number, or you can have another model, you can host multiple websites each on the same ip number and different domain configured as VirtualHost and listening on the same port 80. –  Andrew Smith Jul 8 '12 at 7:58

1 Answer 1

up vote 7 down vote accepted

I think that _default_ is used to define a default vhost in an IP based virtual host configuration. You are using name based virtual hosting so this statement in the documentation

A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts.

becomes relevant.

In a name based virtual host configuration the first vhost defined is the default vhost and it will be served if no other match is found so you could do something simple like

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

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName sub.example.com
    DocumentRoot /var/www/sub.example.com
</VirtualHost>

Would do what you want and serve everything except example.com and sub.example.com from the default.

share|improve this answer

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.