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 am trying to setup Virtual Hosts on Apache that react to the certain subdomains but any domain name

Such as

subxdomain.*

so any domain that points to the machine along with the subxdomain would work

ServerName web.* ...

So web.blahblah.com as well as web.mooose.com will work (both *.blahblah.com and *.mooose.com resolve to the same machine)

share|improve this question

4 Answers 4

The folloging snippet should do the trick:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName subdomain
  ServerAlias subdomain.*
  # other directives for the particular vhost
</VirtualHost>

See the documentation on ServerAlias and Name-based Virtual Host Support for details.

share|improve this answer

I'm not sure if you can use mass vhosts (apache2). i've never done something like this before. http://httpd.apache.org/docs/2.0/vhosts/mass.html

What exactly do you want to achieve with this solution?

share|improve this answer

This should not be hard at all.

By default Apache will respond to all traffic on whatever port you configure it to.

Simply set it to listen to port 80 on the ip that the addresses are assigned to.

Set up a Vhost with a different directory and host name for each named site, and these should take priority over the wild card.

This will resort in all named sites to go where they need to and anything else that the server receives will get the default page.

Just to make sure, I would put the named sites above the wildcard in httpd.conf

share|improve this answer

You cannot use wildcards with ServerName.

What you can do is use the default VirtualHost as a catch-all:

<VirtualHost *:80>
  # NEVER add a ServerName in this VirtualHost
(...)
</VirtualHost>

As long as there is no VirtualHost for web.blahblah.com as well as web.mooose.com they will both work under that default VirtualHost.

You can also use rewrites to redirect requests to different URLs:

  RewriteCond %{HTTP_HOST}      ^web.moose.com$
  RewriteRule ^/(.*)$ http://other.moose.com/web/$1 [R,L]

Hope that helps.

Cheers

share|improve this answer
    
Actually, You can use wildcards on ServerName or ServerAlias directives. –  GetFree Nov 20 '09 at 18:13
1  
Actually, you can use wildcards on ServerAlias but not on ServerName directives. –  joschi Nov 24 '09 at 10:33

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.