up vote 3 down vote favorite
1
share [g+] share [fb]

If I have 3 domains, domain1.com, domain2.com, and domain3.com, is it possible to set up a default virtual host to domains not listed? For example, if I would have:

<VirtualHost 192.168.1.2 204.255.176.199>
DocumentRoot /www/docs/domain1
ServerName domain1
ServerAlias host
</VirtualHost>

<VirtualHost 192.168.1.2 204.255.176.199>
DocumentRoot /www/docs/domain2
ServerName domain2
ServerAlias host
</VirtualHost>

<VirtualHost 192.168.1.2 204.255.176.199>
DocumentRoot /www/docs/everythingelse
ServerName *
ServerAlias host
</VirtualHost>

If you register a domain and point it to my server, it would default to everythingelse showing the same as domain3. Is that possible?

link|improve this question

feedback

3 Answers

up vote 2 down vote accepted

Yes, that should work, except ServerAlias should be "*", with ServerName set to an actual hostname. You might need to make sure that VirtualHost is the very last loaded...

link|improve this answer
It should work, but doesn't. If a domain is not specifically listed, I get "Firefox can't find the server." – SJaguar13 Nov 6 '09 at 22:22
Did you set it as "ServerName host" and "ServerAlias *"? I didn't emphasize this enough originally, but ServerName does not take wildcards, only ServerAlias does. ServerName needs to be an actual hostname. – freiheit Nov 6 '09 at 22:44
Also, do the other virtualhosts work? What version of apache? – freiheit Nov 6 '09 at 22:46
feedback

Don't specify a servername, and that becomes your default vhost..

<VirtualHost *:80>
ServerAdmin webmaster@localhost

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

Also be sure that you haven't specified a DocumentRoot in the main httpd.conf file, as that will take precedence over the vhosts.

link|improve this answer
I have that as the first virtual host listed, and I still get "Firefox can't find the server." – SJaguar13 Nov 8 '09 at 6:18
feedback

Order is important - move your vhost definition for everything else to the head of the list.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.